You really shouldn't try to do something like that if you're on the UI thread, because that will mean you will block the thread. You should instead work around the ref
parameter, for example by accepting a parameter of a simple class type, that contains the value you want to change.
Another reason why not to do this is that it still won't let you use ref
parameters, because lambdas can't access ref
parameters of the enclosing method.
But if you really want to do this (again, I really think you shouldn't), then you will need to get the result of the Task
. Something like:
public string MyCallingMethod()
{
var task = Task.Run(async () =>
{
return await myMethodAsync();
});
return task.Result;
}