473,324 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Is DoEvents a no-no?

Back in VB6, there was "healthy debate" over whether DoEvents should be
used, or it was just too evil ;-)

One can certainly argue that there is a need for a mechanism to have one
routine yield the processor to another. For example, when a file open/save
dialog is closed, the code opening or saving the selected file may want to
allow the application window that was partially occluded by the dialog an
opportunity to repaint itself.

Now in .NET, we have System.Windows.Forms.Application.DoEvents, and this
does indeed seem to provide the required respite, yielding the CPU to other
code in the App.

But is there a better, more general (i.e., not part of the Forms namespace)
way of achieving this? One might consider Thread.Sleep, but it looks like
this blocks the thread all together - a problem if the code you want to
allow to run is to be executed on the same thread.

I'd appreciate any opinions on this topic ...

Thanks.
Sep 15 '06 #1
1 1238
Emby <em**@blaisesoft-xxx.comwrote:
Back in VB6, there was "healthy debate" over whether DoEvents should be
used, or it was just too evil ;-)

One can certainly argue that there is a need for a mechanism to have one
routine yield the processor to another. For example, when a file open/save
dialog is closed, the code opening or saving the selected file may want to
allow the application window that was partially occluded by the dialog an
opportunity to repaint itself.

Now in .NET, we have System.Windows.Forms.Application.DoEvents, and this
does indeed seem to provide the required respite, yielding the CPU to other
code in the App.

But is there a better, more general (i.e., not part of the Forms namespace)
way of achieving this? One might consider Thread.Sleep, but it looks like
this blocks the thread all together - a problem if the code you want to
allow to run is to be executed on the same thread.

I'd appreciate any opinions on this topic ...
The better way is to use a background thread - don't block the UI
thread in the first place.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 15 '06 #2

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

Similar topics

24
by: bazad | last post by:
Hi, I'd like to understand consequences of Application.DoEvents call. Does it create a new thread? Thank you
8
by: Tony | last post by:
Just starting C# from a VB background. Is there a C# keyword comparable to the vb keyword DoEvents? Tony!
50
by: P. Prosper | last post by:
Hello, Could someone give me a hint why my CancelPrint Logic won't work despite the DoEvents ? in form lvele declaration I have Public Shared CancelPrint As Boolean 'Printing Logic Do While...
3
by: Rich | last post by:
As I migrate my VB6 apps to vb.net I am checking what features I need to retain from vb6. In vb6 I noticed that DoEvents really made a performance difference when I called it just before a Do/For...
12
by: Jack Russell | last post by:
My unstanding of all VB up to and including vb6 is that an event could not "interrupt" itself. For instance if you had a timer event containing a msgbox then you would only get one message. ...
7
by: Tym | last post by:
Made the change from vb6 to vb.net and have found that DoEvents() doesn't work!! Well, the replacement System.Windows.Forms.Application.DoEvents() is causing hell!! I have a loop such as
13
by: Amjad | last post by:
Hi, Is there an equivalent to the "Application.Doevents" method in modules or Windows services? I want to make a Windows service that calls a DLL. The DLL would have all my functions and it...
5
by: james.jdunne | last post by:
System.ArgumentException: Item has already been added. Key in dictionary: "-1" Key being added: "-1" at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) at...
4
by: Woo Mun Foong | last post by:
Hi, I have a DLL that is used to carry out some lengthly process. I would like to have something similar to DoEvents that can yield control back to Windows every now and then. Any ideas ? ...
12
by: Justin | last post by:
I can attach my code if anyone wants to see it however I'll try to ask my question with some mark up code first. I'm having a problem terminating my process while using DoEvents. For example: ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.