public MyAwaiter(MyAwaitable awaitable) { this.awaitable = awaitable; if (IsCompleted) { SetResult(); } }
private async void buttonStart_Click(object sender, EventArgs e) { awaitable = new MyAwaitable(); progressBar.Visible = true; var result = await awaitable; //.ConfigureAwait(false); from foreign thread this throws an exception progressBar.Visible = false; MessageBox.Show(result.ToString()); }
static async Task Main() { SynchronizationContext.SetSynchronizationContext(new MySynchronizationContext()); var awaitable = new MyAwaitable(false); var timer = new Timer(_ => awaitable.Finish(), null, 100, -1); var result = await awaitable; Console.WriteLine(result); }
// Need to change the declaration of Main() in order to use 'await' static async Task Main() { // Create a custom awaitable object MyAwaitable awaitable = new MyAwaitable(); // Run awaitable payload, ignore returned Task _ = awaitable.Run(); // Do some other tasks while awaitable is running Console.WriteLine("Waiting for completion..."); // Wait for completion await awaitable; Console.WriteLine("The long operation is now complete. " + awaitable.GetResult()); }
public MyAwaiter(MyAwaitable awaitable) => this.awaitable = awaitable;
public ValueEvent() { Awaitable = new MyAwaitable(); }
public MyAwaiter(MyAwaitable awaitable) { _awaitable = awaitable; }
public MyAwaiter(MyAwaitable awaitable, bool captureContext) { this.awaitable = awaitable; this.captureContext = captureContext; }