c# - Replace thread.sleep with something less intense -


so have learnt previous solution of having "thread.sleep" on c# console application (due waiting web pages stuff can't reach normal webdriverwaits of selenium/chromedriver) not solution, because freezes entire thread entire duration of sleep period.

since shouldn't do: system.threading.thread.sleep(250); should do? want separate statement, not wrapper stuff because gets messy fast. have dozens of places have used thread.sleep. can use entire class - if necessary, want able call normal method.

so far best i've found working:

class tools {     private static async task _sleep(int ms)     {         await task.delay(ms);     }      public static void sleep(int ms)     {         var task = _sleep(ms);         task.wait();     } } 

should replace 1 else?

there reason use form of sleep. in 999 cases out of 1000 bad coding. instead of waiting arbitrary amount of time should wait exact amount of time needed. example should use:

await myfunction(); 

or callback/event handler functions such

webbrowser wb = new webbrowser(); wb.documentcompleted += wb_documentcompleted; ... private void wb_documentcompleted(object sender, webbrowserdocumentcompletedeventargs e)  {    //do thing...  } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -