1
1
using System ;
2
2
using System . Threading ;
3
3
using System . Threading . Tasks ;
4
+ using System . Windows ;
4
5
using System . Windows . Input ;
5
6
using ProgressDialogEx . ProgressDialog ;
6
7
@@ -17,16 +18,18 @@ public MyLongRunningCommand(IProgressDialogService dialogService)
17
18
18
19
public void Execute ( object parameter )
19
20
{
20
- dialogService . Execute ( DoWork , new ProgressDialogOptions { WindowTitle = "Loading files" } ) ;
21
+ Task < int > task = dialogService . ExecuteAsync ( DoWork , new ProgressDialogOptions { WindowTitle = "Loading files" } ) ;
22
+
23
+ MessageBox . Show ( String . Format ( "Result = {0}" , task . Result ) ) ;
21
24
}
22
25
23
- void DoWork ( CancellationToken cancellationToken , IProgress < string > progress )
26
+ static async Task < int > DoWork ( CancellationToken cancellationToken , IProgress < string > progress )
24
27
{
25
- Task . Factory . StartNew ( ( ) => progress . Report ( "First" ) , cancellationToken )
26
- . ContinueWith ( _ => Thread . Sleep ( 1000 ) , cancellationToken )
27
- . ContinueWith ( _ => progress . Report ( "Second" ) , cancellationToken )
28
- . ContinueWith ( _ => Thread . Sleep ( 1000 ) , cancellationToken )
29
- . Wait ( ) ;
28
+ return await Task . Factory . StartNew ( ( ) => progress . Report ( "First" ) , cancellationToken )
29
+ . ContinueWith ( _ => Thread . Sleep ( 1000 ) , cancellationToken )
30
+ . ContinueWith ( _ => progress . Report ( "Second" ) , cancellationToken )
31
+ . ContinueWith ( _ => Thread . Sleep ( 1000 ) , cancellationToken )
32
+ . ContinueWith ( _ => 42 ) ;
30
33
}
31
34
32
35
public bool CanExecute ( object parameter )
0 commit comments