Skip to main content
deleted 1 character in body
Source Link
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 FunctionSynchronousFunction() { Task.Run(Foo).Wait(); } string SynchronousFunctionReturnsString() { return Task.Run(Foo).Result; } string SynchronousFunctionReturnsStringWithParam(int id) { return Task.Run(() => Foo(id)).Result; } 

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; } 

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 SynchronousFunction() { Task.Run(Foo).Wait(); } string SynchronousFunctionReturnsString() { return Task.Run(Foo).Result; } string SynchronousFunctionReturnsStringWithParam(int id) { return Task.Run(() => Foo(id)).Result; } 
edited body
Source Link
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 isit successfully. It will not deadlock the calling thread.

 void SyncFunctionSynchronous Function() { Task.Run(Foo).Wait(); } string SyncFunctionReturnsStringSynchronousFunctionReturnsString() { return Task.Run(Foo).Result; } string SyncFunctionReturnsStringWithParamSynchronousFunctionReturnsStringWithParam(int id) { return Task.Run(() => Foo(id)).Result; } 

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

 void SyncFunction() { Task.Run(Foo).Wait(); } string SyncFunctionReturnsString() { return Task.Run(Foo).Result; } string SyncFunctionReturnsStringWithParam(int id) { return Task.Run(() => Foo(id)).Result; } 

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; } 
added 3 characters in body
Source Link
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 is successfully. It will not blockdeadlock the calling thread.

 void SyncFunction() { Task.Run(Foo).Wait(); } string SyncFunctionReturnsString() { return Task.Run(Foo).Result; } string SyncFunctionReturnsStringWithParam(int id) { return Task.Run(() => Foo(id)).Result; } 

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

 void SyncFunction() { Task.Run(Foo).Wait(); } string SyncFunctionReturnsString() { return Task.Run(Foo).Result; } string SyncFunctionReturnsStringWithParam(int id) { return Task.Run(() => Foo(id)).Result; } 

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

 void SyncFunction() { Task.Run(Foo).Wait(); } string SyncFunctionReturnsString() { return Task.Run(Foo).Result; } string SyncFunctionReturnsStringWithParam(int id) { return Task.Run(() => Foo(id)).Result; } 
Source Link
panpawel
  • 1.8k
  • 1
  • 17
  • 17
Loading