C# Wait until condition is true

后端 未结 7 1607
暖寄归人
暖寄归人 2020-12-24 05:52

I am trying to write a code that executes when a condition is met. Currently, I am using while...loop, which I know is not very efficient. I am also looking at AutoResetEven

7条回答
  •  天命终不由人
    2020-12-24 06:05

    At least you can change your loop from a busy-wait to a slow poll. For example:

        while (!isExcelInteractive())
        {
            Console.WriteLine("Excel is busy");
            await Task.Delay(25);
        }
    

提交回复
热议问题