473,772 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.DoE vents eating messages?

Background:

I am helping someone debug a problem with their form that I have traced to a
strange interaction between a click event handler and Application.DoE vents().
I'm trying to talk him into using mutithreading.

Problem in its essence:

create a simple Form with 2 buttons and a label. button1 starts a
long-running counting process, button 2 stops the counting process. The
first click of the mouse after the button 1 click gets lost. The second and
subsequent clicks work fine.

What's going on?

code snippet (C# .NET 2.0)

bool cancel = false;
int count = 0;

private void button1_Click(o bject sender, EventArgs e)
{
cancel = false;
while (cancel == false)
{
label1.Text = count.ToString( );
Application.DoE vents();
count ++;
}

}

private void button2_Click(o bject sender, EventArgs e)
{
cancel = true;
}

Thanks
--
Joe
Feb 28 '06 #1
2 1532
Why not using timer?

int count = 0;

private void button1_Click(o bject sender, System.EventArg s e)
{
timer1.Enabled = true;
}

private void button2_Click(o bject sender, System.EventArg s e)
{
timer1.Enabled = false;
}

private void timer1_Tick(obj ect sender, System.EventArg s e)
{
label1.Text = count.ToString( );
count ++;
}

You made a loop inside the button1_click event so the event haven't
completed. You can see whatever you click on the form, the focus is still
kept in button1. Therefore, your second click is treated as button1_click
but focus changed to your new control. Then the consequence click works
fines. I don't know whether it is bug or normal behavior. Anyway, looping
for events is not a good programming style.
"joeforbrok e" wrote:
Background:

I am helping someone debug a problem with their form that I have traced to a
strange interaction between a click event handler and Application.DoE vents().
I'm trying to talk him into using mutithreading.

Problem in its essence:

create a simple Form with 2 buttons and a label. button1 starts a
long-running counting process, button 2 stops the counting process. The
first click of the mouse after the button 1 click gets lost. The second and
subsequent clicks work fine.

What's going on?

code snippet (C# .NET 2.0)

bool cancel = false;
int count = 0;

private void button1_Click(o bject sender, EventArgs e)
{
cancel = false;
while (cancel == false)
{
label1.Text = count.ToString( );
Application.DoE vents();
count ++;
}

}

private void button2_Click(o bject sender, EventArgs e)
{
cancel = true;
}

Thanks
--
Joe

Feb 28 '06 #2
"Tedmond" wrote:
Why not using timer?


Thanks for your response.

I agree that looping for events is not good programming style.

A timer works well for this simple example. In the real program, the button
click starts a lon-running process that can't be broken up into discrete
steps the way that incrementing a variable can. I believe the right choice
in this particular case is running a worker thread.

Be that as it may, there still seems to be a bug or at least undocumented
weirdness in calling Application.DoE vents() from a Click event handler. If
the handler does not call DoEvents() the second click is delivered correctly
(after the handler finishes running). If it does call DoEvents() the second
click never arrives anywhere. Third and subsequent clicks all work correctly.

If this is normal behavior, then the Application.DoE vents() examples that
I've seen also have problems.

--
Joe


Feb 28 '06 #3

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
609
by: foldface | last post by:
Hi I am doing drag and drop between controls (listview and treeview) using mouse_event. What I am after is a book/resource to explain the behaviour below. If I do the various Win32 api calls and call Application.Run, it works. I can see dragging and dropping on the screen. If I do this:
6
4300
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...
3
2926
by: Lumpierbritches | last post by:
I have an application my partner wrote that would allow an autoresponse to any Mapi compliant email that apparently in .Net won't, can someone assist me with fixing this? Here is the code: Utilities Module: Option Explicit Option Base 1
8
6508
by: TrtnJohn | last post by:
I have an application where I would like to block waiting on an asynchronous event and still process messages. I can implement a hard loop to block such as: Do While StillWaiting Application.DoEvents Loop In this case the asynchronous thread can just set StillWaiting=False when complete.
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.
8
381
by: Jeremy S. | last post by:
Application.DoEvents(); Why would I ever want to do that? When is it (1) required, or (2) a "good idea" or (3) a "bad idea" Thanks.
0
9621
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
10106
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...
1
10039
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
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
8937
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...
1
7461
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6716
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
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4009
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.