public MyAwaiter(MyAwaitable awaitable)
 {
     this.awaitable = awaitable;
     if (IsCompleted)
     {
         SetResult();
     }
 }
Пример #2
0
    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());
    }
Пример #3
0
    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);
    }
Пример #4
0
    // 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());
    }
Пример #5
0
 public MyAwaiter(MyAwaitable awaitable) => this.awaitable = awaitable;
Пример #6
0
 public ValueEvent()
 {
     Awaitable = new MyAwaitable();
 }
Пример #7
0
 public MyAwaiter(MyAwaitable awaitable)
 {
     _awaitable = awaitable;
 }
 public MyAwaiter(MyAwaitable awaitable, bool captureContext)
 {
     this.awaitable      = awaitable;
     this.captureContext = captureContext;
 }