-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_AwaitCatchFinally.cs
80 lines (68 loc) · 1.38 KB
/
07_AwaitCatchFinally.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Threading.Tasks;
//
// All exmaples are taken from MS Roslyn Codeplex page
// https://www.codeplex.com/Download?ProjectName=roslyn&DownloadId=824694
//
namespace CSharp6Samples_AwaitCatchFinally
{
#region CSharp 5 Not possible
public class AwaitCatchFinallyV5
{
private async void Method ()
{
Resource res = null;
try
{
res = await Resource.OpenAsync ();
}
catch (Exception e)
{
var task = Resource.LogAsync (res, e);
task.Wait();
}
finally
{
var task = res.CloseAsync ();
task.Wait ();
}
}
}
#endregion
#region CSharp 6
public class AwaitCatchFinallyV6
{
private async void Method ()
{
Resource res = null;
try
{
res = await Resource.OpenAsync ();
}
catch (Exception e)
{
await Resource.LogAsync (res, e);
}
finally
{
if (res != null) await res.CloseAsync ();
}
}
}
#endregion
public class Resource
{
internal static Task<Resource> OpenAsync ()
{
throw new NotImplementedException ();
}
internal static Task LogAsync (Resource res, Exception e)
{
throw new NotImplementedException ();
}
internal Task CloseAsync ()
{
throw new NotImplementedException ();
}
}
}