How to simulate Application.DoEvents in a DLL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
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?
 
Import System.Threading, then just use

Thread.Sleep(0)

Does practically the same thing as Application.DoEvents - especially from a
dll.
___________________________
The Grim Reaper
 
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
 
Back
Top