xxxxxxxxxx
var task = MyAsyncMethod();
var result = task.WaitAndUnwrapException();
xxxxxxxxxx
// Old synchronous methods
public void OldMethod()
{
// regular synchronous code go here...
}
public string OldMethodWithReturnValue()
{
// regular synchronous code go here...
return "string result here...";
}
// New asynchronous methods
public async Task NewMethodAsync()
{
await Task.Run(() =>
{
// regular synchronous code go here...
});
}
public async Task<string> NewMethodWithReturnValueAsync()
{
string result = await Task.Run(() =>
{
// regular synchronous code go here...
return "string result here...";
});
return result;
}