当我最小化应用程序时无法恢复它
我编写了一个 C# 桌面应用程序,当我让它等待特定事件时(如下所示的循环......)
while (tf.Exists)
{
System.Threading.Thread.Sleep(100);
System.Windows.Forms.Application.DoEvents();
}
我可以与我的应用程序交互并将其最小化,但我无法让它恢复。 有时我会一边低声咒骂一边猛烈地点击鼠标按钮来恢复它,但大多数情况下它不会恢复。 有谁知道我在循环中做错了什么?
谢谢,
格雷格
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不知道这段代码是如何开始的,这是不可能重现的。无论如何,你永远不想这样做,它允许用户关闭你的主窗口。现在您的循环仍在运行,但没有用户界面。
请改用计时器。在处理程序中执行其 Tick 事件的检查。
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(这很少是有效的方法)。
Rather than polling and calling
DoEvents
, which is seldom an effective approach, arrange for the event of interest to send you a message or fire an event.