PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET How to simulate Application.DoEvents in a DLL

Reply

How to simulate Application.DoEvents in a DLL

 
Thread Tools Rate Thread
Old 18-10-2006, 03:14 AM   #1
=?Utf-8?B?V29vIE11biBGb29uZw==?=
Guest
 
Posts: n/a
Default How to simulate Application.DoEvents in a DLL


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
  Reply With Quote
Old 18-10-2006, 03:44 AM   #2
Spam Catcher
Guest
 
Posts: n/a
Default Re: How to simulate Application.DoEvents in a DLL

=?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.




  Reply With Quote
Old 18-10-2006, 03:51 AM   #3
Smokey Grindel
Guest
 
Posts: n/a
Default Re: How to simulate Application.DoEvents in a DLL

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



  Reply With Quote
Old 18-10-2006, 09:31 PM   #4
The Grim Reaper
Guest
 
Posts: n/a
Default Re: How to simulate Application.DoEvents in a DLL

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



  Reply With Quote
Old 19-10-2006, 07:37 PM   #5
Theo Verweij
Guest
 
Posts: n/a
Default Re: How to simulate Application.DoEvents in a DLL

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

>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off