@@ -1,30 +1,30 | |||
|
1 | 1 | using System.Windows.Forms; |
|
2 | 2 | using System; |
|
3 | 3 | |
|
4 | 4 | |
|
5 | 5 | namespace Implab.Fx { |
|
6 | 6 | public class ControlBoundPromise<T> : Promise<T> { |
|
7 | 7 | readonly Control m_target; |
|
8 | 8 | |
|
9 | 9 | public ControlBoundPromise(Control target) { |
|
10 | 10 | Safe.ArgumentNotNull(target, "target"); |
|
11 | 11 | |
|
12 | 12 | m_target = target; |
|
13 | 13 | } |
|
14 | 14 | |
|
15 |
public ControlBoundPromise(Control target, IPromise parent |
|
|
16 |
: base(parent |
|
|
15 | public ControlBoundPromise(Control target, IPromise parent) | |
|
16 | : base(parent) { | |
|
17 | 17 | Safe.ArgumentNotNull(target, "target"); |
|
18 | 18 | |
|
19 | 19 | m_target = target; |
|
20 | 20 | } |
|
21 | 21 | |
|
22 | 22 | protected override void InvokeHandler(HandlerDescriptor handler) { |
|
23 | 23 | if (m_target.InvokeRequired) |
|
24 | 24 | m_target.BeginInvoke(new Action<HandlerDescriptor>(base.InvokeHandler), handler); |
|
25 | 25 | else |
|
26 | 26 | base.InvokeHandler(handler); |
|
27 | 27 | } |
|
28 | 28 | } |
|
29 | 29 | } |
|
30 | 30 |
@@ -1,41 +1,41 | |||
|
1 | 1 | using System; |
|
2 | 2 | using System.Windows.Forms; |
|
3 | 3 | using System.Threading; |
|
4 | 4 | |
|
5 | 5 | namespace Implab.Fx |
|
6 | 6 | { |
|
7 | 7 | public static class PromiseHelpers |
|
8 | 8 | { |
|
9 | 9 | /// <summary> |
|
10 | 10 | /// Перенаправляет обработку обещания в поток указанного элемента управления. |
|
11 | 11 | /// </summary> |
|
12 | 12 | /// <typeparam name="T">Тип результата обещания</typeparam> |
|
13 | 13 | /// <param name="that">Исходное обещание</param> |
|
14 | 14 | /// <param name="ctl">Элемент управления</param> |
|
15 | 15 | /// <returns>Новое обещание, обработчики которого будут выполнены в потоке элемента управления.</returns> |
|
16 | 16 | /// <exception cref="ArgumentNullException">Параметр не может быть <c>null</c>.</exception> |
|
17 | 17 | /// <example> |
|
18 | 18 | /// client |
|
19 | 19 | /// .Get("description.txt") // returns a promise |
|
20 | 20 | /// .DispatchToControl(m_ctl) // handle the promise in the thread of the control |
|
21 | 21 | /// .Then( |
|
22 | 22 | /// description => m_ctl.Text = description // now it's safe |
|
23 | 23 | /// ) |
|
24 | 24 | /// </example> |
|
25 | 25 | public static IPromise<T> DispatchToControl<T>(this IPromise<T> that, Control ctl) |
|
26 | 26 | { |
|
27 | 27 | Safe.ArgumentNotNull(that, "that"); |
|
28 | 28 | Safe.ArgumentNotNull(ctl, "ctl"); |
|
29 | 29 | |
|
30 |
var directed = new ControlBoundPromise<T>(ctl,that |
|
|
30 | var directed = new ControlBoundPromise<T>(ctl,that); | |
|
31 | 31 | |
|
32 | 32 | that.Last( |
|
33 | 33 | directed.Resolve, |
|
34 | 34 | directed.Reject, |
|
35 | 35 | directed.Cancel |
|
36 | 36 | ); |
|
37 | 37 | |
|
38 | 38 | return directed; |
|
39 | 39 | } |
|
40 | 40 | } |
|
41 | 41 | } |
General Comments 0
You need to be logged in to leave comments.
Login now