473,473 Members | 4,185 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
Oct 18 '06 #1
4 10896
=?Utf-8?B?V29vIE11biBGb29uZw==?= <mf***@yahoo.comwrote in
news:F4**********************************@microsof t.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.


Oct 18 '06 #2
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" <mf***@yahoo.comwrote in message
news:F4**********************************@microsof t.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

Oct 18 '06 #3
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" <mf***@yahoo.comwrote in message
news:F4**********************************@microsof t.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

Oct 18 '06 #4
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" <mf***@yahoo.comwrote in message
news:F4**********************************@microsof t.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

Oct 19 '06 #5

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
6
by: Ollie Riches | last post by:
I understand the use of Application.DoEvents() to process all outstanding messages on the message queue in a winforms application if you have long running process on the UI thread. But can anyone...
1
by: Viet | last post by:
I don't know if this is the right forum for my question but here goes: I am converting a VB6 app to VB.NET and I would like to use Threads and Threadpools. This main app (1) executes two other sub...
0
by: Ralf Gedrat | last post by:
Hello! I have a Application, this throws after some time following exception: Item has already been added. Key in dictionary: "- 1" key being added: "- 1" I use Application.Run with...
1
by: RSH | last post by:
I created a new Windows Form project and I created a simple richtextbox to write to and I am looping through a simple example but obviously the screen isn't updated it only shows the first...
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...
16
by: Alan T | last post by:
I tried to use a thread to process a iterative execution of processes but afraid my thread is not thread-safe. If I am not using a thread, my main form will become 'white' when switch forth and...
11
by: Don | last post by:
I have a WPF application in VB in VSTS 2008 RTM. I am trying to "blink" (momentarily clear) a field of data if the data is reloaded from the database to give the user some visual indication of the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.