1

I have a .Net Framework 4.8 WinForms app which was initially developed over a decade ago before Tasks was a thing in .Net. Until today the app has never had to worry itself with using Tasks, but the day has finally come.

There is one dependency injection service that needs a new implementation. It needs to get data from a REST service so will be using the System.Net.Http.HttpClient with all of its Task-based methods.

How does one go about making calls into the System.Net.Http.HttpClient when it is not possible to add async to the calling class?

Sam Carleton
  • 1,339
  • 7
  • 23
  • 45
  • Possible, yes. But not recommended. .GetAwaiter().GetResult(). How were you doing that before? – Paulo Morgado Dec 12 '22 at 16:06
  • Does this answer your question? [How to use HttpClient without async](https://stackoverflow.com/questions/40208647/how-to-use-httpclient-without-async) – Peter Csala Dec 16 '22 at 12:21
  • I have found openapi-generator-cli to be the easiest way to generate a .Net Framework client to access the RESTful service, so I have gone that route: https://openapi-generator.tech/docs/generators/csharp-netcore/ – Sam Carleton Dec 26 '22 at 14:24

0 Answers0