Dofactory.com
Dofactory.com

How to call an asynchronous method from a synchronous method in C#.

Use the Result property on the asynchronous Task, like so:


// Synchronous method

void Method() 
{
    var task = MethodAsync();
    var result = task.Result;
}

// Asynchronous method

public async Task<int> MethodAsync() 
{
    return await Task.Run(() => { return 1; });
}


Jack Poorte
Jack Poorte
Last updated on Sep 30, 2023



Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.