linux-packaging-mono/mcs/tests/test-async-78.cs
Xamarin Public Jenkins 6992685b86 Imported Upstream version 4.2.0.179
Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
2015-11-10 14:54:39 +00:00

54 lines
991 B
C#

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;
}
}