-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleClass.cs
27 lines (22 loc) · 856 Bytes
/
SampleClass.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
using System;
using System.Threading;
using System.Threading.Tasks;
namespace AsyncInterceptor
{
public class SampleClass
{
public virtual async Task Foo(bool throwException)
{
Console.WriteLine("Foo here, I see: " + throwException);
Console.WriteLine($"Foo will delay asynchronously a bit (thread before: {Thread.CurrentThread.ManagedThreadId})");
await Task.Delay(TimeSpan.FromSeconds(2.0));
Console.WriteLine($"Foo again after the delay (thread after: {Thread.CurrentThread.ManagedThreadId})");
if (throwException)
{
Console.WriteLine("Foo throwing exception as instructed");
throw new InvalidOperationException("Exception requested");
}
Console.WriteLine("Foo returning");
}
}
}