PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
How to simulate Application.DoEvents in a DLL
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
How to simulate Application.DoEvents in a DLL
![]() |
How to simulate Application.DoEvents in a DLL |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 ? Thank You, mfwoo |
|
|
|
#2 |
|
Guest
Posts: n/a
|
=?Utf-8?B?V29vIE11biBGb29uZw==?= <mfwoo@yahoo.com> wrote in
news:F4D9622B-F1C6-476B-9BC5-1A380E14C671@microsoft.com: > 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. Rather than us Application.DoEvents, you call the long running processes using a delegate or thread. The delegate or thread can be created on the Caller Side... or wrapped in the DLL. The choice is yours. The long running process would raise events to inform the caller of the progress of the process. |
|
|
|
#3 |
|
Guest
Posts: n/a
|
You'd have to pass a refernce to the function for the application object,
however, why don't you just run the DLL's function in a seperate thread with a call back method to report progress? "Woo Mun Foong" <mfwoo@yahoo.com> wrote in message news:F4D9622B-F1C6-476B-9BC5-1A380E14C671@microsoft.com... > 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 ? > > > Thank You, > mfwoo |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Import System.Threading, then just use
Thread.Sleep(0) Does practically the same thing as Application.DoEvents - especially from a dll. ___________________________ The Grim Reaper "Woo Mun Foong" <mfwoo@yahoo.com> wrote in message news:F4D9622B-F1C6-476B-9BC5-1A380E14C671@microsoft.com... > 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 ? > > > Thank You, > mfwoo |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Not completely.
DoEvents invokes the next message in the application messagequeue, and can change the codeflow within your current thread (if your on the application main thread). Sleep suspends the thread for the specified amount of time, giving windows time to run other threads. Sleep(0) just ends the current timeslice for the current thread. A nice way to see the difference: do: doevents: loop gives almost 100% cpu usage, but you can break the process thanks to the invoke of the messagequeue. do: sleep(0): loop gives almost 0% cpu usage, but you cannot break the process (you can end it with the debugger - in vb6 it will hang your IDE) So, in short, sleep(x) will make all other applications and other threads in your application more responsive, except for the thread your code is running on (if this is the application main thread, your application will not be more responsive, and may even be seen as not responding in the task manager). The main thread of your application can only made to be more responsive by using DoEvents or, in your case, the code provided in: http://www.nirsoft.net/vb/doevents.html The Grim Reaper wrote: > Import System.Threading, then just use > > Thread.Sleep(0) > > Does practically the same thing as Application.DoEvents - especially from a > dll. > ___________________________ > The Grim Reaper > > "Woo Mun Foong" <mfwoo@yahoo.com> wrote in message > news:F4D9622B-F1C6-476B-9BC5-1A380E14C671@microsoft.com... >> 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 ? >> >> >> Thank You, >> mfwoo > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

