程序繁忙时需要显示一条消息 [英] need to show a message while program is busy

查看:84
本文介绍了程序繁忙时需要显示一条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hellow

,我想向用户显示一条消息,说他/她应该等待几秒钟

当程序忙于检测微软单词是否正常工作时

当程序完成检测上述消息后应该消失

看到此代码

hellow
in the code below ,i want to show a message to the user saying that he/she should wait for few seconds
while the program is busy in detecting whether the microsoft word is working or not
when program finish detecting the above message should disappear
see this code

//MyMessage("Please wait");//<-------- line A
    foreach (System.Diagnostics.Process instance in Process.GetProcesses())
    {
        if (instance.ProcessName == "WINWORD")
        {
             flage = 1;
        }
    }
    //MyMessage should disappear here//<--- line B



我应该在A行和B行写什么

谢谢


what should i write in both line A and line B
thanks

推荐答案

我这样做的方法是创建一个包含消息的表单,在后台线程或Shown事件处理程序中执行GetProcesses(后台更好),完成后关闭。

然后在主窗体的消息表单中使用ShowDialog,当表单关闭时它会返回,这样你就可以得到结果。
The way I would do it is to create a form which holds the message and which either does the GetProcesses in a background thread or in the Shown event handler (background is better) and closes when it is done.
You then use ShowDialog on the message form in your main form and it returns when the form closes so you can get the result.


您应该将程序的检测部分放在工作线程上,以保持GUI响应。请查看线程(MSDN) [ ^ ]。
You should put the 'detecting part' of your program on a worker thread in order to keep the GUI responsive. Have a look at Threading (MSDN)[^].


这篇关于程序繁忙时需要显示一条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆