473,769 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.DoE vents()

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 fro between other applications. So now I tried
Application.DoE vents(). But it seems does not help, my main form still
displays as 'white' when switch between other application.
Oct 12 '06 #1
16 12925
Hi Alan,

What Application.DoE vents is doing is halt the current processing and
process pending events before continuing, but to make your form responsive
you would need to call DoEvents several times per second. If you are
unable to split your processing into small chunks that can be interrupted
with a DoEvents, you will need to use another thread.
On Thu, 12 Oct 2006 08:50:37 +0200, Alan T <al************ *@yahoo.com.au>
wrote:
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 fro between other applications. So now I tried
Application.DoE vents(). But it seems does not help, my main form still
displays as 'white' when switch between other application.



--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 12 '06 #2
So this is basically what I am doing:
Press a button on main form, execute a loop, execute a third party
application inside each loop.

Click other applicaton on task bar and click my application, my main form is
white now.

"Morten Wennevik" <Mo************ @hotmail.comwro te in message
news:op******** *******@tr024.b ouvet.no...
Hi Alan,

What Application.DoE vents is doing is halt the current processing and
process pending events before continuing, but to make your form responsive
you would need to call DoEvents several times per second. If you are
unable to split your processing into small chunks that can be interrupted
with a DoEvents, you will need to use another thread.
On Thu, 12 Oct 2006 08:50:37 +0200, Alan T <al************ *@yahoo.com.au>
wrote:
>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 fro between other applications. So now I tried
Application.Do Events(). But it seems does not help, my main form still
displays as 'white' when switch between other application.


--
Happy Coding!
Morten Wennevik [C# MVP]

Oct 13 '06 #3

"Alan T" <al************ *@yahoo.com.auw rote in message
news:eR******** ******@TK2MSFTN GP04.phx.gbl...
| So this is basically what I am doing:
| Press a button on main form, execute a loop, execute a third party
| application inside each loop.
|

What exactly do you mean here? you can't execute another application withing
an application!
Please post some code, or be more explicit.

Willy.
Oct 13 '06 #4
Sorry if my explanation was not clear:

I got a main form, by pressing a button a looping process will be executed
(while loop), for example 100 times.
Inside this loop, I will execute a third-party application (eg. abc.exe).

This is so far so good.

However, if I click other application on the taskbar, for example, Windows
Explorer, IE,... etc and then click my application, my main form will be
blank.
So what I think is I need to add Application.DoE vents() inside my while
loop.

After I added Application.DoE vents() in some places inside my click event
handler and inside my while loop, it gave some improvements. But sometimes
the response is still so slow and sometimes gave me blank screen on my main
form.

"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:eL******** ******@TK2MSFTN GP02.phx.gbl...
>
"Alan T" <al************ *@yahoo.com.auw rote in message
news:eR******** ******@TK2MSFTN GP04.phx.gbl...
| So this is basically what I am doing:
| Press a button on main form, execute a loop, execute a third party
| application inside each loop.
|

What exactly do you mean here? you can't execute another application
withing
an application!
Please post some code, or be more explicit.

Willy.


Oct 16 '06 #5
I'm guessing it takes some time to fire up the other processes.

In any case, for such simple tasks Threading shouldn't be too hard to
learn.

See Jon Skeet's article on multi-threading
http://www.yoda.arachsys.com/csharp/threads/

On Mon, 16 Oct 2006 02:19:27 +0200, Alan T <al************ *@yahoo.com.au>
wrote:
Sorry if my explanation was not clear:

I got a main form, by pressing a button a looping process will be
executed
(while loop), for example 100 times.
Inside this loop, I will execute a third-party application (eg. abc.exe).

This is so far so good.

However, if I click other application on the taskbar, for example,
Windows
Explorer, IE,... etc and then click my application, my main form will be
blank.
So what I think is I need to add Application.DoE vents() inside my while
loop.

After I added Application.DoE vents() in some places inside my click event
handler and inside my while loop, it gave some improvements. But
sometimes
the response is still so slow and sometimes gave me blank screen on my
main
form.

"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:eL******** ******@TK2MSFTN GP02.phx.gbl...
>>
"Alan T" <al************ *@yahoo.com.auw rote in message
news:eR******* *******@TK2MSFT NGP04.phx.gbl.. .
| So this is basically what I am doing:
| Press a button on main form, execute a loop, execute a third party
| application inside each loop.
|

What exactly do you mean here? you can't execute another application
withing
an application!
Please post some code, or be more explicit.

Willy.




--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 16 '06 #6
Just to add to what Morten said, you should never ever execute something
that takes more than a couple of 100 msec. (and even this might be
disturbing) inside a UI handler. In your handler you are spawning an
external application and you probably wait until this external process
terminates (you better do so!), this will take longer than a few 100 msec,
right?, well don't do this, handle this to an auxiliary thread, and you
don't need this DoEvents any longer.

Willy.


"Alan T" <al************ *@yahoo.com.auw rote in message
news:OL******** ******@TK2MSFTN GP03.phx.gbl...
| Sorry if my explanation was not clear:
|
| I got a main form, by pressing a button a looping process will be executed
| (while loop), for example 100 times.
| Inside this loop, I will execute a third-party application (eg. abc.exe).
|
| This is so far so good.
|
| However, if I click other application on the taskbar, for example, Windows
| Explorer, IE,... etc and then click my application, my main form will be
| blank.
| So what I think is I need to add Application.DoE vents() inside my while
| loop.
|
| After I added Application.DoE vents() in some places inside my click event
| handler and inside my while loop, it gave some improvements. But sometimes
| the response is still so slow and sometimes gave me blank screen on my
main
| form.
|
| "Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
| news:eL******** ******@TK2MSFTN GP02.phx.gbl...
| >
| "Alan T" <al************ *@yahoo.com.auw rote in message
| news:eR******** ******@TK2MSFTN GP04.phx.gbl...
| | So this is basically what I am doing:
| | Press a button on main form, execute a loop, execute a third party
| | application inside each loop.
| |
| >
| What exactly do you mean here? you can't execute another application
| withing
| an application!
| Please post some code, or be more explicit.
| >
| Willy.
| >
| >
|
|
Oct 16 '06 #7
I tried a using thread and it solved my problem.
But, how do I detect the thread is finished ?

"Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
Just to add to what Morten said, you should never ever execute something
that takes more than a couple of 100 msec. (and even this might be
disturbing) inside a UI handler. In your handler you are spawning an
external application and you probably wait until this external process
terminates (you better do so!), this will take longer than a few 100 msec,
right?, well don't do this, handle this to an auxiliary thread, and you
don't need this DoEvents any longer.

Willy.


"Alan T" <al************ *@yahoo.com.auw rote in message
news:OL******** ******@TK2MSFTN GP03.phx.gbl...
| Sorry if my explanation was not clear:
|
| I got a main form, by pressing a button a looping process will be
executed
| (while loop), for example 100 times.
| Inside this loop, I will execute a third-party application (eg.
abc.exe).
|
| This is so far so good.
|
| However, if I click other application on the taskbar, for example,
Windows
| Explorer, IE,... etc and then click my application, my main form will be
| blank.
| So what I think is I need to add Application.DoE vents() inside my while
| loop.
|
| After I added Application.DoE vents() in some places inside my click
event
| handler and inside my while loop, it gave some improvements. But
sometimes
| the response is still so slow and sometimes gave me blank screen on my
main
| form.
|
| "Willy Denoyette [MVP]" <wi************ *@telenet.bewro te in message
| news:eL******** ******@TK2MSFTN GP02.phx.gbl...
| >
| "Alan T" <al************ *@yahoo.com.auw rote in message
| news:eR******** ******@TK2MSFTN GP04.phx.gbl...
| | So this is basically what I am doing:
| | Press a button on main form, execute a loop, execute a third party
| | application inside each loop.
| |
| >
| What exactly do you mean here? you can't execute another application
| withing
| an application!
| Please post some code, or be more explicit.
| >
| Willy.
| >
| >
|
|


Oct 17 '06 #8

Alan T wrote:
I tried a using thread and it solved my problem.
But, how do I detect the thread is finished ?
You don't actually "detect" that the thread is finished.

Instead, you have the method that runs in the background thread use
this.Invoke to make a call to another method, this time back in the UI
context, and in there do whatever you need to do now that the thread is
finished.

For example, I do some heavy processing when a user presses a button.

1. The button1_Clicked method that handles the button click disables
all of the controls on the form and then starts a new thread and has it
run DoHeavyProcessi ng.

2. At the end of DoHeavyProcessi ng, I do a this.Invoke() to run
DoneProcessing method on the UI thread.

3. DoneProcessing( ) then re-enables all of the controls on the form.

The final effect is that when the user presses the button, the form
changes so that he can't manipulate anything, but he can still minimize
it, maximize it, drag it around, etc. When the background process is
done the form's controls are re-enabled and the user can continue
working.

Oct 17 '06 #9
Can you elaborate about step (2) ?
How does the DoneProcessing on the UI thread be called by this.Invoke() ?

"Bruce Wood" <br*******@cana da.comwrote in message
news:11******** **************@ f16g2000cwb.goo glegroups.com.. .
>
Alan T wrote:
>I tried a using thread and it solved my problem.
But, how do I detect the thread is finished ?

You don't actually "detect" that the thread is finished.

Instead, you have the method that runs in the background thread use
this.Invoke to make a call to another method, this time back in the UI
context, and in there do whatever you need to do now that the thread is
finished.

For example, I do some heavy processing when a user presses a button.

1. The button1_Clicked method that handles the button click disables
all of the controls on the form and then starts a new thread and has it
run DoHeavyProcessi ng.

2. At the end of DoHeavyProcessi ng, I do a this.Invoke() to run
DoneProcessing method on the UI thread.

3. DoneProcessing( ) then re-enables all of the controls on the form.

The final effect is that when the user presses the button, the form
changes so that he can't manipulate anything, but he can still minimize
it, maximize it, drag it around, etc. When the background process is
done the form's controls are re-enabled and the user can continue
working.

Oct 17 '06 #10

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

Similar topics

24
3292
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
4299
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 explain to me why I need to call DoEvents when I am using a COM component that calls back to into the ..Net application? - If I don't call DoEvents after receiving a callback then sometimes no more messages are pumped, it appears that the message...
1
1749
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 apps: app 2 and app 3. In app 2, the original vb6 program utilized the form timers to execute 4 main routines in which one of these routines would constantly poll a Canon scanner for the user to scan in documents. I recoded app2 so that it would...
0
4210
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 ApplicationContext. This error message comes from deeper levels must be thrown (mscorlib.dll?!) ?.
1
5965
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 occurance. I have used Application DoEvents in the past to update the screen which works. but for some reason in this project when i use Application.DoEvents i get the error... "DoEvents() Is not a member of DTS.Application" How do I make the...
13
10105
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 would be doing all the job, but some of the functions that I'm using require calling something like "Application.Doevents" and I can't use this because the DLL module is not an application.
5
4579
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 System.Collections.Hashtable.Add(Object key, Object value) at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FRegisterComponent(IMsoComponent component, MSOCRINFOSTRUCT pcrinfo, Int32& dwComponentID) at...
4
10930
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 ? Thank You,
11
5177
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 LOAD operation. So on the LOAD button I clear the text fields, do mainCanvas.UpdateLayout( ), and the reload the text field from the database. But the text fields are not cleared long enough to see them blink.
3
8219
by: Sathyaish | last post by:
From inside a class library, in a WPF application, I wish to get a handle to an object, any object, may be the System.Windows.Application object that supports a method such as DoEvents() by calling which, I can force the control to yeild to the operating system so that the UI thread is not blocked, and the dispatcher is not suspended. Can you please help?
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
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 we have to send another system

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.