简体   繁体   中英

Cannot restore appication when I minimize it

I have written a C# Desktop Application and when I have it waiting for a specific event (in a loop like as follows...

while (tf.Exists)
{
    System.Threading.Thread.Sleep(100);
    System.Windows.Forms.Application.DoEvents();
}

I can inteact with my application and minimize it, but I cannot get it to restore. Sometimes I get it to restore by clicking furiously with my mouse buttons while mumbling curses under my breath, but for the most part it will not restore. Does anyone know what I am doing wrong in my loop?

Thanks ,

Greg

This is impossible to repro without knowing how this code got started. You never want to do it this way anyway, it allows the user to close your main window. Now your loop is still running but without a user interface.

Use a Timer instead. Perform the check in a handler for its Tick event.

与其轮询和调用DoEvents (很少是一种有效的方法),不如安排感兴趣的事件向您发送消息或触发事件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM