Trying to understand how Tasks and async/await

It seems everything turns out to make work asynchronously, but this line is not (

 Browser = new OpenQA.Selenium.Chrome.ChromeDriver(); 
  • one
    You look like a man with a hammer, for whom everything looks like nails ... - Sergey
  • 2
    @ Sergey now, that's the way it is, therefore I ask questions. - Vipz

1 answer 1

To make something synchronous work asynchronously, we wrap it in:

 await Task.Factory.StartNew(()=> { // ΠΊΠ°ΠΊΠΎΠΉ-Ρ‚ΠΎ синхронный ΠΊΠΎΠ΄ }); 

Or so (from the comments, yes, and more correctly, perhaps):

 await Task.Run(()=> { // ΠΊΠ°ΠΊΠΎΠΉ-Ρ‚ΠΎ синхронный ΠΊΠΎΠ΄ }); 

But this should be done rarely and cautiously - in fact, only long operations (IO and calculations), and then if there is no asynchronous version ... There are a lot of nuances and problems - this solution is hard on the head. In short, you can, but you do not need.

  • one
    You can also add an answer with the option await Task.Run() => {/** some code */} - Ep1demic