本文介绍了EnableVisualStyles和DoEvents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我注意到在Sub Main中调用Application.EnableVisualStyles的应用程序中调用DoEvents要慢得多。此外,每次调用DoEvents时性能似乎都会恶化。 要演示我正在体验的内容,请使用Sub Main,Main Form和Button创建一个应用程序(称为Button1)。在Sub Main中包含以下代码: Application.EnableVisualStyles Application.DoEvents Application.Run(New MainForm) 现在,在Button1的Click事件处理程序中包含以下代码: For i As Integer = 1到8000 Application.DoEvents 下一页我是b $ b在我的系统上第一次单击Button1需要大约0.92秒。随后的点击次数为1.35,1.72,2.12和2.52秒。但是,如果我现在从Sub Main中删除Application.EnableVisualStyles,那么单击Button1只需要约0.07秒(如果我继续单击Button1,时间不会增加)。 这是一个已知的问题?有修复吗?是否有助于通过清单文件启用视觉样式而不是调用EnableVisualStyles? 我在Windows XP Pro(SP1)上使用.NET Framework v1.1。 谢谢, LanceI''ve noticed that calling DoEvents is much slower in an application that has called Application.EnableVisualStyles in Sub Main. Furthermore, the performance seems to worsen each time that DoEvents is called.To demonstrate what I''m experiencing, create an app with a Sub Main, a Main Form, and a Button (called Button1). Include the following code in Sub Main:Application.EnableVisualStylesApplication.DoEventsApplication.Run(New MainForm)Now, include the following code in the Click event handler of Button1:For i As Integer = 1 to 8000Application.DoEventsNext iOn my system the first time that I click Button1 takes ~0.92 seconds. Subsequent clicks take 1.35, 1.73, 2.12, and 2.52 seconds. But, if I now remove Application.EnableVisualStyles from Sub Main, then clicking Button1 only takes ~0.07 seconds (and the time does not increase if I continue to click Button1).Is this a known issue? Is there a fix? Would it help to enable visual styles via a manifest file rather than calling EnableVisualStyles?I''m using .NET Framework v1.1 on Windows XP Pro (SP1).Thanks,Lance推荐答案 为什么这是一个问题,需要修复什么? DoEvents可以花费任何时间来支付,具体取决于您排队的消息数量。因此,如果您对完成所需的时间做出任何假设,那么您就会遇到问题。 我不明白为什么任何人都会在任何 真实代码中循环调用DoEvents 8000次。 Mattias - Mattias Sj?gren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com 请回复到新闻组。Why is it an issue at all, and what needs to be fixed? DoEvents cantake any amount of time, depending on how many messages you havequeued up. So if you make any assumptions on the time it will take tocomplete, you''re asking for problems.I don''t see why anyone would call DoEvents 8000 times in a loop in anyreal code.Mattias--Mattias Sj?gren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.comPlease reply only to the newsgroup. 这篇关于EnableVisualStyles和DoEvents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-12 10:26