Skip to main content
3 of 4
edited body
panpawel
  • 1.8k
  • 1
  • 17
  • 17

Here is the simplest solution. I saw it somewhere on the Internet, I didn't remember where, but I have been using it successfully. It will not deadlock the calling thread.

 void Synchronous Function() { Task.Run(Foo).Wait(); } string SynchronousFunctionReturnsString() { return Task.Run(Foo).Result; } string SynchronousFunctionReturnsStringWithParam(int id) { return Task.Run(() => Foo(id)).Result; } 
panpawel
  • 1.8k
  • 1
  • 17
  • 17