单例消息框
我正在编写一个应用程序,其中当连接发生问题时,我想弹出一个消息框并向用户显示错误...
为此目的,当程序抛出异常时,它将进入 catch 块,并且我想要向用户显示消息,这里是代码:
catch (WebException ex)
{
if (!(ex.Message == "The operation has timed out."))
{
MessageBox.Show(ex.Message);
}
}
因为看起来程序会永远捕获类似的东西,直到连接修复,所以我应该怎么做才能一次只更新一个消息框上的消息?
I am writing an application in which when something happened to the connection I want to pop up a messagebox and show the user the error...
for this purpose when the program throw an exception it will come to the catch block and in that I want to show the user the message here is the code :
catch (WebException ex)
{
if (!(ex.Message == "The operation has timed out."))
{
MessageBox.Show(ex.Message);
}
}
As it seems the program will come to this catch something like forever till the connection is become fixed so what should I do to update my message on just one messagebox at a time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MessageBox
显示时没有太多控制。我将使用另一个以模态模式显示的Form
。在显示之前,您可以启动一个单独的线程并放置监视连接的逻辑。重新建立后,通知消息表单并将其关闭。There is not much control over
MessageBox
when it's displayed. I would use anotherForm
displayed in a modal mode. Before displaying, you can start a separate thread and put the logic to monitor the connection. When re-established, notify the message form and close it.您可以使用类似的内容:
示例用法:
You can use something like:
Sample usage: