-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSyncOverAsync.cs
52 lines (44 loc) · 1.44 KB
/
SyncOverAsync.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.Threading.Tasks;
class SyncOverAsync : IRunnable
{
public Task Run()
{
return this.WrapInContext(() =>
{
BlocksAndPotentiallyDeadlocks();
//BlocksAndPotentiallyDeadlocks2();
// BlocksUsesDefaultScheduler();
});
}
string BlocksAndPotentiallyDeadlocks()
{
return this.DoAsyncOperation().GetAwaiter().GetResult();
}
string BlocksAndPotentiallyDeadlocks2()
{
var task = this.DoAsyncOperation();
task.Wait(1000); // timeout deliberately added
return task.GetAwaiter().GetResult();
}
string BlocksUsesDefaultScheduler()
{
return Task.Run(() => this.DoAsyncOperation()).GetAwaiter().GetResult();
}
// other very creative approaches
string BlocksUsesDefaultSchedulerThrowsAggregateException()
{
return Task.Run(() => this.DoAsyncOperation()).Result;
}
string BlocksUsesDefaultSchedulerThrowsAggregateExceptionWithAggregateException()
{
return Task.Run(() => this.DoAsyncOperation().Result).Result;
}
string BlocksThreadThatEntersAndThreadPoolThreadInside()
{
return Task.Run(() => this.DoAsyncOperation().GetAwaiter().GetResult()).GetAwaiter().GetResult();
}
string BlocksCapturesContextPotentiallyDeadlocksThrowsAggregateException()
{
return this.DoAsyncOperation().Result;
}
}