Awaiting a non-async method
26,235
Call your method as following:
await Task.Run(() => YourMethod());
When you use the Task.Run method it creates an awaitable task for you.
Comments
-
NibblyPig over 3 years
I'm thoroughly confused by the whole await / async pattern in C#.
I have a forms app, and I want to call a method that takes 20 seconds to do a ton of processing. Therefore I want to
await
it. I thought the correct way was to mark it asasync Task
but doing this produces a warning because I don't useawait
anywhere within it.A google revealed something about returning a
TaskCompletionSource<T>
but I don't have a return type, since it's void.How can I call this method using
await
?