EnableVisualStyles和DoEvents [英] EnableVisualStyles and DoEvents

查看:64
本文介绍了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。


谢谢,

Lance

I''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.EnableVisualStyles
Application.DoEvents
Application.Run(New MainForm)

Now, include the following code in the Click event handler of Button1:

For i As Integer = 1 to 8000
Application.DoEvents
Next i

On 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

推荐答案

因为如何变得越来越糟你的呼叫是在

GDI消息队列中堆积东西并导致它加载到很多...不要叫它

如此接近每个另外,真的没有那个

" Lance" <滋*** @ hotmail.com>在消息中写道

news:55 ********************************** @ microsof t.com ...
it''s getting worse because of how your calling it is pileing up stuff on the
GDI message queue and causeing it to load up with to much... don''t call it
so close to each other, there really is no nead for that
"Lance" <zi***@hotmail.com> wrote in message
news:55**********************************@microsof t.com...
我注意到在
在Sub Main中调用Application.EnableVisualStyles的应用程序中调用DoEvents要慢得多。此外,每次调用DoEvents时,

的性能似乎都会恶化。
要演示我正在体验的内容,请创建一个带有Sub Main的应用程序,
主表单和一个Button(称为Button1)。在Sub中包含以下代码
Main:
Application.EnableVisualStyles
Application.DoEvents
Application.Run(New MainForm)

现在,在Button1的Click事件处理程序中包含以下代码:

对于i as Integer = 1到8000
Application.DoEvents
下一页我是

在我的系统上,我第一次点击Button1需要大约0.92秒。
后续点击需要1.35,1.72,2.12和2.52秒。但是,如果我现在

从Sub Main中删除Application.EnableVisualStyles,然后单击Button1

只需要约0.07秒(如果我继续
单击Button1)。
这是一个已知问题吗?有修复吗?是否有助于通过清单文件启用visual
样式而不是调用EnableVisualStyles?
我在Windows XP Pro(SP1)上使用.NET Framework v1.1。
谢谢,
Lance
I''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.EnableVisualStyles
Application.DoEvents
Application.Run(New MainForm)

Now, include the following code in the Click event handler of Button1:

For i As Integer = 1 to 8000
Application.DoEvents
Next i

On 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



这是一个已知问题吗?是否有修复?
Is this a known issue? Is there a fix?




为什么这是一个问题,需要修复什么? 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 can
take any amount of time, depending on how many messages you have
queued up. So if you make any assumptions on the time it will take to
complete, you''re asking for problems.

I don''t see why anyone would call DoEvents 8000 times in a loop in any
real code.

Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


听起来这是一个合理的问题不是吗?


我在一个博客上注意到发布了以下内容如果您使用的是v1.1

框架并遇到SEHException并且不知道是什么造成了

它,请检查看看你是否调用了Application.EnableVisualStyles()。显然是

,这是SEHExceptions出现的许多问题的根源。


和另一个问题。这似乎是由于一个错误在EnableVisualStyles中你需要在调用

Application.EnableVisualStyles之后调用Application.DoEvents,否则你的图像列表将无法正常工作

更多。希望这有助于某人。 Simon发表于2003年9月24日04:53

PM"


和第三个看起来由于EnableVisualStyles中的错误你

必须在调用

Application.EnableVisualStyles之后调用Application.DoEvents,否则你的图像列表将无法正常工作

更多。希望这有助于某人。 Simon发表于2003年9月24日4:53

PM"


最终我找到了解释其中的大部分内容:
http://weblogs.asp.net /rprabhu/archi.../28/56540.aspx


有些事情发生了,这揭示了其中一个问题。

的替代方案是发布3000行代码并运行一小时?

:-)


我打赌
It sounds like a reasonable question doesn''t it?

I note on one blog that the following was posted "If you''re using v1.1 of
the Framework and encounter an SEHException and have no idea what''s causing
it, check to see if you called Application.EnableVisualStyles(). Apparently
that is the source for a number of problems that appear as SEHExceptions."

And on another "It would appear that due to a bug in EnableVisualStyles you
have to call Application.DoEvents after the call to
Application.EnableVisualStyles or your image lists won''t work properly any
more. Hope this helps someone. Posted by Simon at September 24, 2003 04:53
PM"

And on a third "It would appear that due to a bug in EnableVisualStyles you
have to call Application.DoEvents after the call to
Application.EnableVisualStyles or your image lists won''t work properly any
more. Hope this helps someone. Posted by Simon at September 24, 2003 4:53
PM"

Ultimately I found this which explains much of it:

http://weblogs.asp.net/rprabhu/archi.../28/56540.aspx

It doesn''t matter if the guy noticed it calling DoEvents 8000 times
something is up and that revealed one of the problems. What would the
alternative be to post 3000 lines of code and as you to run it for an hour?
:-)

I''ll bet


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

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