Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mcs] Use reference from closest storey which holds captured this. Fi…
…xes #29506
- Loading branch information
1 parent
691f540
commit 8e3e9d8
Showing
3 changed files
with
140 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
public static class ExceptionHelper | ||
{ | ||
public static async Task ConditionalCatchExceptThreadAbortAsync (Func<Task> | ||
funcTask, Action<Exception> conditionalCatchAction) | ||
{ | ||
funcTask (); | ||
return; | ||
} | ||
} | ||
|
||
class ATask | ||
{ | ||
readonly object _asyncTaskCancellationSource = new object (); | ||
|
||
readonly object aname; | ||
|
||
public async Task<bool> OnDoWorkAsync () | ||
{ | ||
await ExceptionHelper.ConditionalCatchExceptThreadAbortAsync ( | ||
async () => { | ||
if (_asyncTaskCancellationSource != null) { | ||
string item = null; | ||
await ExceptionHelper.ConditionalCatchExceptThreadAbortAsync ( | ||
async () => { | ||
Console.WriteLine (aname); | ||
}, | ||
(e) => { | ||
Console.WriteLine (item); | ||
} | ||
); | ||
} | ||
}, | ||
null | ||
); | ||
|
||
return true; | ||
} | ||
} | ||
|
||
public class Tests | ||
{ | ||
public static void Main () | ||
{ | ||
var a = new ATask (); | ||
var res = a.OnDoWorkAsync ().Result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters