473,769 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

EnableVisualSty les and DoEvents

I've noticed that calling DoEvents is much slower in an application that has called Application.Ena bleVisualStyles 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.Ena bleVisualStyles
Application.DoE vents
Application.Run (New MainForm)

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

For i As Integer = 1 to 8000
Application.DoE vents
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.Ena bleVisualStyles 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 EnableVisualSty les?

I'm using .NET Framework v1.1 on Windows XP Pro (SP1).

Thanks,
Lance
Nov 20 '05 #1
17 2399
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******** *************** ***********@mic rosoft.com...
I've noticed that calling DoEvents is much slower in an application that has called Application.Ena bleVisualStyles 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.Ena bleVisualStyles
Application.DoE vents
Application.Run (New MainForm)

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

For i As Integer = 1 to 8000
Application.DoE vents
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.Ena bleVisualStyles 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 EnableVisualSty les?
I'm using .NET Framework v1.1 on Windows XP Pro (SP1).

Thanks,
Lance

Nov 20 '05 #2
Is this a known issue? Is there a fix?


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.
Nov 20 '05 #3
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.Ena bleVisualStyles (). 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 EnableVisualSty les you
have to call Application.DoE vents after the call to
Application.Ena bleVisualStyles 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 EnableVisualSty les you
have to call Application.DoE vents after the call to
Application.Ena bleVisualStyles 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 $10 that we don't get a belated reply from one of the MS guys
thanking us for the question. :-)
"Mattias Sjögren" <ma************ ********@mvps.o rg> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Is this a known issue? Is there a fix?


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.

Nov 20 '05 #4
Lance,
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.Ena bleVisualStyles from Sub Main,
then clicking Button1 only takes ~0.07 seconds
(and the time does not increase if I continue to click Button1). How are you timing this? Which version of VS.NET (2003 or Whidbey)?

In VS.NET 2003 under Windows XP Pro, I get the following numbers:

With EnableVisualSty les:
Sum: 0.7151978812949 64
Avg: 8.9399735161870 5E-05
Min: 4.7771434637642 5E-05
Max: 0.1501425460498 47
Count: 8000
StDev: 0.0016865126980 5306
Var: 2.8443250806942 1E-06

Without EnableVisualSty les:
Sum: 0.1058472515361 68
Avg: 1.3230906442021 E-05
Min: 8.9396836748804 7E-06
Max: 0.0041779052924 3242
Count: 8000
StDev: 8.3665359383228 E-05
Var: 6.9998923607247 E-09

Even with EnableVisualSty les: yes the numbers are larger, however they are
definitely sub second times in both cases!

Looking at the XML file created it appears that the numbers drop off (it
speeds up) after about 30 iterations, in both cases.

BTW: Here is the code I used to get the above numbers:

Declare Function QueryPerformanc eCounter Lib "Kernel32" (ByRef X As
Long) As Short
Declare Function QueryPerformanc eFrequency Lib "Kernel32" (ByRef X As
Long) As Short

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim frequency As Long
QueryPerformanc eFrequency(freq uency)

Dim ds As New DataSet("DoEven ts")
Dim dt As New DataTable("DoEv ents")
dt.Columns.Add( "start", GetType(Long))
dt.Columns.Add( "finish", GetType(Long))
dt.Columns.Add( "seconds", GetType(Double) )
dt.Columns.Add( "time", GetType(Long), "finish - start")
ds.Tables.Add(d t)
Dim start, finish As Long
For i As Integer = 1 To 8000
QueryPerformanc eCounter(start)
Application.DoE vents()
QueryPerformanc eCounter(finish )
Dim seconds As Double = (finish - start) / frequency
dt.Rows.Add(New Object() {start, finish, seconds})
Next i
ds.WriteXml("Do Events.xml")
Debug.WriteLine (dt.Compute("Su m(seconds)", Nothing), "Sum")
Debug.WriteLine (dt.Compute("Av g(seconds)", Nothing), "Avg")
Debug.WriteLine (dt.Compute("Mi n(seconds)", Nothing), "Min")
Debug.WriteLine (dt.Compute("Ma x(seconds)", Nothing), "Max")
Debug.WriteLine (dt.Compute("Co unt(seconds)", Nothing), "Count")
Debug.WriteLine (dt.Compute("St Dev(seconds)", Nothing), "StDev")
Debug.WriteLine (dt.Compute("Va r(seconds)", Nothing), "Var")
End Sub

Personally, this seems to be largely academic, DoEvents processes all the
events in you Win32 message queue, which means you have no real control over
how long DoEvents itself is going to take, does it really matter that it
takes a fraction of a second longer (based on the above numbers)?

Hope this helps
Jay

"Lance" <zi***@hotmail. com> wrote in message
news:55******** *************** ***********@mic rosoft.com... I've noticed that calling DoEvents is much slower in an application that has called Application.Ena bleVisualStyles 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.Ena bleVisualStyles
Application.DoE vents
Application.Run (New MainForm)

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

For i As Integer = 1 to 8000
Application.DoE vents
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.Ena bleVisualStyles 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 EnableVisualSty les?
I'm using .NET Framework v1.1 on Windows XP Pro (SP1).

Thanks,
Lance

Nov 20 '05 #5
Hi Lance,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.

From your description, I understand that when you call EnableVisualSty les
and then doevents in a button click event, every time you click the button
the times will increase to call 8000 times doevents.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Now I am researching the issue, if I have new information I will update you
with new information ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #6
Cor
Hi Jay B,

Thanks for that test code, looks interesting.

Cor
Nov 20 '05 #7
What you said is correct, although I also noticed that it significantly longer to call DoEvents when visual styles are enabled. Thanks for your help.

Lance

Nov 20 '05 #8
Thanks for the example!

The reason for my interest is when DoEvents is called from within a long loop in order for an app to respond to the user while the loop is executing. I thought that this technique was faily common. Am I wrong? Is there a better way? If not, then it seems to me that in this case having DoEvents take 13+ times longer can be an issue, depending on the size and structure of the loops.

Thanks again,
Lance
Nov 20 '05 #9
> The reason for my interest is when DoEvents is called
from within a long loop in order for an app to respond to
the user while the loop is executing. I thought that
this technique was faily common. Am I wrong? Is there a better way?
It was common in VB6 because there was no supported concept of threads. With
the addition of managed threads to VB.net, the general practice is to spawn
your own thread to do background processing and leave the user interface
thread to respond to user input. This way, DoEvents is not needed.

Here's some links that may help you out with threading:

http://tinyurl.com/383zg
http://tinyurl.com/373zl
http://msdn.microsoft.com/library/en...asp?frame=true
Be careful of some of the complexities of threading though (e.g. Don't call
a method on a form or control from a different thread without using
Invoke(), be careful when sharing data between threads etc.)

Threading is not recommended for all types of loops though. For example, if
you are populating a listview from an a datatable, don't use a separate
thread to do this - the numerous calls between threads when adding items
will be very slow. Instead I tend to do this by:

1) Spawn a thread to get the datatable from the database - UI won't lock
while this is happening
2) Call back the main thread, pass in the datatable, display a wait cursor
and fill the list (with doevents if a BIG list).

Of course if your background thread is doing processing that doesn't involve
data shared with the form, go ahead and use a thread.

Hth,

Trev.

"Lance" <zi***@hotmail. com> wrote in message
news:36******** *************** ***********@mic rosoft.com... Thanks for the example!

The reason for my interest is when DoEvents is called from within a long loop in order for an app to respond to the user while the loop is executing.
I thought that this technique was faily common. Am I wrong? Is there a
better way? If not, then it seems to me that in this case having DoEvents
take 13+ times longer can be an issue, depending on the size and structure
of the loops.
Thanks again,
Lance

Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
293
by: Sylvain Barde | last post by:
When I use Application.EnableVisualStyles() Public Sub New() MyBase.New() Application.EnableVisualStyles() Application.DoEvents()
4
334
by: #ROBERT | last post by:
(VS 2003 + .NET Framework 1.1 + WinXP Pro SP2) Calling Application.EnableVisualStyles() after the initialization() removes all images in the tab control (in the tab headers I mean). Without visual styles enabled, I have no problem. What is wrong and what is the solution? (PS: Using a manifest file makes no trouble. just the function : Application.EnableVisualStyles() ) Thanks for any help.
1
1634
by: desa | last post by:
If I call EnableVisualStyles none the images in my ImageLists show up in my controls anymore. Is this a known issue? How do I fix this? I'm using VS.NET 2003.
5
3380
by: mphanke | last post by:
Hi, everytime I enable the Visualstyles on in my app it keeps crashing at a point, where I close my progress window with progressdialog.close(). It runs in a seperate thread and contains a timer and a progressbar- if this is of interest. Best regards, Martin
4
1888
by: Christian Westerlund | last post by:
Hi! I usually enable visual styles in my apps. I do it in Main before I start my app with Application.Run. Today when I changed from debug to release mode in Visual Studio .NET 2003, the XP-style disappeared when I ran the app. I changed back to debug mode but I couldn't get the more appealing XP-style back. I even created a new solution and projects and manually copied my files
2
1622
by: Juan Pedro Gonzalez | last post by:
I am a bit unsure about this "Effect"... My code: Public Sub Main() Application.EnableVisualStyles() Application.DoEvents() Dim myMainForm As New FormularioPrincipal Dim mySplash As New MyClass.SplashScreen If mySplash.ShowDialog() = DialogResult.OK Then
3
2331
by: Michael A. Covington | last post by:
I added Application.EnableVisualStyles() as the first statement in Main() of my program, and didn't notice much change in visual appearance, but what I *did* notice is that some of my buttons stopped working! They were enabled but no longer called their OnClick methods. I tried adding Application.DoEvents() right after EnableVisualStyles and that didn't help. What gives? In VS 2005/.NET 2.0, is EnableVisualStyles broken? This is...
3
1439
by: Michael A. Covington | last post by:
Further to previous post... I have a big, complex program which works fine as long as I don't call EnableVisualStyles. If I do this: Application.EnableVisualStyles(); Application.DoEvents(); Application.Run(new FormOpeningMenu());
7
1219
by: Peter | last post by:
Hello, I'm using Visual Studio 2003 and it would be nice if my buttons and other controls could look like Windows XP buttons rather than the flat square kind. I looked on the web and found some info on Application.EnableVisualStyles, but I'm not seeing much indication that 2003 supports it. Does it? And if so, how does it work?
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.