@@ -33,15 +33,10 @@ public async Task SocketAsyncEventArgs_ExecutionContextFlowsAcrossAcceptAsyncOpe
33
33
} ;
34
34
35
35
asyncLocal . Value = 42 ;
36
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
37
- try
36
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
38
37
{
39
38
Assert . True ( listener . AcceptAsync ( saea ) ) ;
40
39
}
41
- finally
42
- {
43
- if ( suppressContext ) ExecutionContext . RestoreFlow ( ) ;
44
- }
45
40
asyncLocal . Value = 0 ;
46
41
47
42
client . Connect ( listener . LocalEndPoint ) ;
@@ -65,19 +60,14 @@ public async Task APM_ExecutionContextFlowsAcrossBeginAcceptOperation(bool suppr
65
60
var tcs = new TaskCompletionSource < int > ( ) ;
66
61
67
62
asyncLocal . Value = 42 ;
68
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
69
- try
63
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
70
64
{
71
65
listener . BeginAccept ( iar =>
72
66
{
73
67
listener . EndAccept ( iar ) . Dispose ( ) ;
74
68
tcs . SetResult ( asyncLocal . Value ) ;
75
69
} , null ) ;
76
70
}
77
- finally
78
- {
79
- if ( suppressContext ) ExecutionContext . RestoreFlow ( ) ;
80
- }
81
71
asyncLocal . Value = 0 ;
82
72
83
73
client . Connect ( listener . LocalEndPoint ) ;
@@ -105,15 +95,10 @@ public async Task SocketAsyncEventArgs_ExecutionContextFlowsAcrossConnectAsyncOp
105
95
106
96
bool pending ;
107
97
asyncLocal . Value = 42 ;
108
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
109
- try
98
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
110
99
{
111
100
pending = client . ConnectAsync ( saea ) ;
112
101
}
113
- finally
114
- {
115
- if ( suppressContext ) ExecutionContext . RestoreFlow ( ) ;
116
- }
117
102
asyncLocal . Value = 0 ;
118
103
119
104
if ( pending )
@@ -139,19 +124,14 @@ public async Task APM_ExecutionContextFlowsAcrossBeginConnectOperation(bool supp
139
124
140
125
bool pending ;
141
126
asyncLocal . Value = 42 ;
142
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
143
- try
127
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
144
128
{
145
129
pending = ! client . BeginConnect ( listener . LocalEndPoint , iar =>
146
130
{
147
131
client . EndConnect ( iar ) ;
148
132
tcs . SetResult ( asyncLocal . Value ) ;
149
133
} , null ) . CompletedSynchronously ;
150
134
}
151
- finally
152
- {
153
- if ( suppressContext ) ExecutionContext . RestoreFlow ( ) ;
154
- }
155
135
asyncLocal . Value = 0 ;
156
136
157
137
if ( pending )
@@ -182,15 +162,10 @@ public async Task SocketAsyncEventArgs_ExecutionContextFlowsAcrossDisconnectAsyn
182
162
183
163
bool pending ;
184
164
asyncLocal . Value = 42 ;
185
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
186
- try
165
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
187
166
{
188
167
pending = client . DisconnectAsync ( saea ) ;
189
168
}
190
- finally
191
- {
192
- if ( suppressContext ) ExecutionContext . RestoreFlow ( ) ;
193
- }
194
169
asyncLocal . Value = 0 ;
195
170
196
171
if ( pending )
@@ -220,19 +195,14 @@ public async Task APM_ExecutionContextFlowsAcrossBeginDisconnectOperation(bool s
220
195
221
196
bool pending ;
222
197
asyncLocal . Value = 42 ;
223
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
224
- try
198
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
225
199
{
226
200
pending = ! client . BeginDisconnect ( reuseSocket : false , iar =>
227
201
{
228
202
client . EndDisconnect ( iar ) ;
229
203
tcs . SetResult ( asyncLocal . Value ) ;
230
204
} , null ) . CompletedSynchronously ;
231
205
}
232
- finally
233
- {
234
- if ( suppressContext ) ExecutionContext . RestoreFlow ( ) ;
235
- }
236
206
asyncLocal . Value = 0 ;
237
207
238
208
if ( pending )
@@ -267,17 +237,12 @@ public async Task SocketAsyncEventArgs_ExecutionContextFlowsAcrossReceiveAsyncOp
267
237
saea . RemoteEndPoint = server . LocalEndPoint ;
268
238
269
239
asyncLocal . Value = 42 ;
270
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
271
- try
240
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
272
241
{
273
242
Assert . True ( receiveFrom ?
274
243
client . ReceiveFromAsync ( saea ) :
275
244
client . ReceiveAsync ( saea ) ) ;
276
245
}
277
- finally
278
- {
279
- if ( suppressContext ) ExecutionContext . RestoreFlow ( ) ;
280
- }
281
246
asyncLocal . Value = 0 ;
282
247
283
248
server . Send ( new byte [ ] { 18 } ) ;
@@ -306,8 +271,7 @@ public async Task APM_ExecutionContextFlowsAcrossBeginReceiveOperation(bool supp
306
271
var tcs = new TaskCompletionSource < int > ( ) ;
307
272
308
273
asyncLocal . Value = 42 ;
309
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
310
- try
274
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
311
275
{
312
276
EndPoint ep = server . LocalEndPoint ;
313
277
Assert . False ( receiveFrom ?
@@ -322,11 +286,6 @@ public async Task APM_ExecutionContextFlowsAcrossBeginReceiveOperation(bool supp
322
286
tcs . SetResult ( asyncLocal . Value ) ;
323
287
} , null ) . CompletedSynchronously ) ;
324
288
}
325
- finally
326
- {
327
- if ( suppressContext )
328
- ExecutionContext . RestoreFlow ( ) ;
329
- }
330
289
asyncLocal . Value = 0 ;
331
290
332
291
server . Send ( new byte [ ] { 18 } ) ;
@@ -365,18 +324,13 @@ public async Task SocketAsyncEventArgs_ExecutionContextFlowsAcrossSendAsyncOpera
365
324
366
325
bool pending ;
367
326
asyncLocal . Value = 42 ;
368
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
369
- try
327
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
370
328
{
371
329
pending =
372
330
sendMode == 0 ? client . SendAsync ( saea ) :
373
331
sendMode == 1 ? client . SendToAsync ( saea ) :
374
332
client . SendPacketsAsync ( saea ) ;
375
333
}
376
- finally
377
- {
378
- if ( suppressContext ) ExecutionContext . RestoreFlow ( ) ;
379
- }
380
334
asyncLocal . Value = 0 ;
381
335
382
336
int totalReceived = 0 ;
@@ -416,8 +370,7 @@ public async Task APM_ExecutionContextFlowsAcrossBeginSendOperation(bool suppres
416
370
417
371
bool pending ;
418
372
asyncLocal . Value = 42 ;
419
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
420
- try
373
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
421
374
{
422
375
pending = sendTo ?
423
376
! client . BeginSendTo ( buffer , 0 , buffer . Length , SocketFlags . None , server . LocalEndPoint , iar =>
@@ -431,10 +384,6 @@ public async Task APM_ExecutionContextFlowsAcrossBeginSendOperation(bool suppres
431
384
tcs . SetResult ( asyncLocal . Value ) ;
432
385
} , null ) . CompletedSynchronously ;
433
386
}
434
- finally
435
- {
436
- if ( suppressContext ) ExecutionContext . RestoreFlow ( ) ;
437
- }
438
387
asyncLocal . Value = 0 ;
439
388
440
389
int totalReceived = 0 ;
@@ -477,19 +426,14 @@ public async Task APM_ExecutionContextFlowsAcrossBeginSendFileOperation(bool sup
477
426
478
427
bool pending ;
479
428
asyncLocal . Value = 42 ;
480
- if ( suppressContext ) ExecutionContext . SuppressFlow ( ) ;
481
- try
429
+ using ( suppressContext ? ExecutionContext . SuppressFlow ( ) : default )
482
430
{
483
431
pending = ! client . BeginSendFile ( filePath , iar =>
484
432
{
485
433
client . EndSendFile ( iar ) ;
486
434
tcs . SetResult ( asyncLocal . Value ) ;
487
435
} , null ) . CompletedSynchronously ;
488
436
}
489
- finally
490
- {
491
- if ( suppressContext ) ExecutionContext . RestoreFlow ( ) ;
492
- }
493
437
asyncLocal . Value = 0 ;
494
438
495
439
if ( pending )
0 commit comments