Saturday, 15 January 2011

loops - C# Wait until condition is true -


I am trying to write a code that is conditioned when executed. Currently, I am using that time ... loop, which I know is not very efficient, I'm also looking at AutoResetEvent () but I do not know how to implement it, as long as it The situation is not correct until it keeps checking.

The code is also meant to stay inside an async method, can there be any kind of waiting?

Private async zero btnOk_Click (Object Sender, EventArgs E) {// Some Tasks & lt; String & gt; Function = action.Run (() => greatbig method ()); String greatbigimip = awaiting work; // Wait until the situation is incorrect (! IsExcelInteractive ()) {Console.WriteLine ("Excel is busy"); } // Work Console Wrightite ("YAY"); } Private Bull is Excel Interactive (try {try {globals} ThisWorkbook.Application.Interactive = Globals.ThisWorkbook.Application.Interactive; Back true; // Excel is free} hold {return false; / / Excel will throw an exception, which means its busy}}

me isExcelInteractive () find a way to get caught in the loop without any CPU

Note : Excel has no event handler, it will be raised when it is not in editing mode.

At least you can gradually change your loop from a busy wait to the survey. For example:

  while (! IsExcelInteractive ()) {Console.WriteLine ("Excel is busy"); Awaiting work Daley (25); }  

No comments:

Post a Comment