替代Application.DoEvents() [英] Alternative to Application.DoEvents()

查看:285
本文介绍了替代Application.DoEvents()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发基于web浏览器控件,这样我可以然而格式文本我请一个消息系统。当用户处于脱机状态并且发送邮件时,邮件存储和为每个消息,当他们再次登录时发送的事件当我设置为网站的默认HTML和这样的,我通常使用:

I am developing a messaging system based on webBrowser controls so that I can format the text however I please. When the user is offline and is sent messages, the messages are stored and an event is sent for every message when they log back in. When I set the default html and such for the website, I normally use:

while (this.webBrowser1.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents();

当程序正常运行这个工程。如果当他们处于离线状态,用户接收发送的信息,这将触发下一个消息事件等,每个邮件,直到最后一个。这意味着,当它们是离线发送的最后一条消息是显示唯一的一个。我想类似Application.DoEvents(),允许控制,以保持更新和加载,但不会触发其他事件。

This works when the program is running normally. When the user is receiving message sent when they are offline, this triggers the next message event and so on, with each message until the last one. This means that the last message sent when they are offline is the only one displayed. I'd like something like Application.DoEvents() that allows the control to keep updating and loading, but that doesn't trigger other events.

感谢

编辑:

我由()完全删除的DoEvents解决了这一问题。相反,改变DocumentText作为我的工作,我成立了一个字符串生成器,然后在年底成立的HTML的一次。

I fixed the problem by removing DoEvents() completely. Instead of changing the DocumentText as I worked, I set up a string builder and then set the html all at once at the end.

推荐答案

我建议你停止使用 Application.DoEvents(),它产生的问题比它解决。检查<一href=\"http://stackoverflow.com/questions/5181777/c-application-doevents/5183623#5183623\">this.

I recommend you to stop using Application.DoEvents(), it is generate problems more than it solves. check this.

有一个更好的方法可以是使用的AutoResetEvent 通知每当载入已完成,或只要加载完成后引发的事件。也可以运行在另一个线程等待所以不必使用 Application.DoEvents() ...

A better way is either use an AutoResetEvent to notify whenever loading completed, or by raising an event whenever the loading is done. also you can run your waiting on another thread so don't have to use Application.DoEvents()...

这篇关于替代Application.DoEvents()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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