473,626 Members | 3,221 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

While(true)Appl ication.DoEvent s V Application.Run

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:

while(true)
{
Application.DoE vents()
}

it works, while if I do this:

while(true)
{
FormFinder finder = new FormFinder();
FormCollection theForms = finder.FindAll( "Employee Transfers");
if(theForms.Cou nt > 0) break;
Application.DoE vents()
}

it doesn't work. The code is NUintForms b.t.w.
Its almost as if theres a timing issue involved, you have to be looking
at the queue at the right minute?

Any advice?

Thanks
F

Nov 22 '05 #1
6 4754
<fo******@yahoo .co.uk> wrote:
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:

while(true)
{
Application.DoE vents()
}

it works, while if I do this:

while(true)
{
FormFinder finder = new FormFinder();
FormCollection theForms = finder.FindAll( "Employee Transfers");
if(theForms.Cou nt > 0) break;
Application.DoE vents()
}

it doesn't work. The code is NUintForms b.t.w.
Its almost as if theres a timing issue involved, you have to be looking
at the queue at the right minute?

Any advice?


Application.Run is a much nicer way of handling things, I think.
Certainly a tight loop on Application.DoE vents is a bad idea.

Shouldn't your test be

if (theForms.Count == 0) break;

though - so you stop processing events when all forms have been closed,
rather than when none of them have been closed?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #2
I'm waiting for a form to appear, hence the code.
I'm trying to use DoEvent to keep to the structure of NUnitForms. Is
there a way of exiting the Application.Run once its running?

I would like to know how the internals work?

Nov 22 '05 #3
<fo******@yahoo .co.uk> wrote:
I'm waiting for a form to appear, hence the code.
I'm trying to use DoEvent to keep to the structure of NUnitForms. Is
there a way of exiting the Application.Run once its running?
It stops when the form which is passed to it is closed.
I would like to know how the internals work?


I can't help you there, although others no doubt can.

It feels like a bad idea to manually call the message pump like this.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #4
As far as I can see, Application.Run kicks off a non-modal message loop, and
as Jon says will carry on running until the form is closed.
Application.DoE vents also kicks off a message loop (actually the same one as
Run), however since no form is set for this message loop it won't exit the
loop when the form is closed, but rather once the message pump has been
emptied.

When dealing with forms, it is much better to rely on the Framework to
handle the messaging for you (via Form.Show, Form.ShowDialog &
Application.Run ) unless you have a really deep understanding of the windows
message pump.

<fo******@yahoo .co.uk> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
I'm waiting for a form to appear, hence the code.
I'm trying to use DoEvent to keep to the structure of NUnitForms. Is
there a way of exiting the Application.Run once its running?

I would like to know how the internals work?

Nov 22 '05 #5
> When dealing with forms, it is much better to rely on the Framework
to
handle the messaging for you (via Form.Show, Form.ShowDialog &
Application.Run ) unless you have a really deep understanding of the windows message pump.


This is purely for testing using NUnit. NUnitForms seems to rely on
Application.DoE vents and I was trying to work with that. Instead
I'm now doing something like

[Test]
public void Test1()
{
// make my form, etc
Thread thread = new Thread(new ThreadStart(Oth erMethod));
thread.Start();
Application.Run ()
}

public void OtherMethod()
{
// wait for a bit, do some stuff with the forms
Application.Exi t()
}

repeat for other tests.

but this is the best I've come up with rather than 'the' way to do it.
It would
be nice to have a real understanding of how DoEvents and Run works so
that
I have the option of doing it anyway I want. Also I just like knowing
how things work.

Ta
F

Nov 22 '05 #6
I'd spelunk them with Reflector to find out the nitty-gritty's, but my
earlier post gave the gist of it. The message loop is fairly simple:
1. Call PeekMessage to get messages for current thread. If there aren't any
and it's not a form loop then exit out of the loop
2. Call GetMessage on the current thread, and create a Message object from
it.
3. If it's a control, call PreProcessMessa ge on it, jumping to 6 if the
message was handled.
4. Translate virtual key codes messages to character messages
5. Dispatch the message to it's target
6. If this is for a form, and it's not closing, back to 1

(I've simplified it a bit, but you get the idea)

As I said before, DoEvents executes this procedure without a specific form,
Run(Form) the indicated form, and ShowDialog(Form ) runs it with various
modal options set.

<fo******@yahoo .co.uk> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
When dealing with forms, it is much better to rely on the Framework

to
handle the messaging for you (via Form.Show, Form.ShowDialog &
Application.Run ) unless you have a really deep understanding of the

windows
message pump.


This is purely for testing using NUnit. NUnitForms seems to rely on
Application.DoE vents and I was trying to work with that. Instead
I'm now doing something like

[Test]
public void Test1()
{
// make my form, etc
Thread thread = new Thread(new ThreadStart(Oth erMethod));
thread.Start();
Application.Run ()
}

public void OtherMethod()
{
// wait for a bit, do some stuff with the forms
Application.Exi t()
}

repeat for other tests.

but this is the best I've come up with rather than 'the' way to do it.
It would
be nice to have a real understanding of how DoEvents and Run works so
that
I have the option of doing it anyway I want. Also I just like knowing
how things work.

Ta
F

Nov 22 '05 #7

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

Similar topics

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:
0
1661
by: Jonathan Trevor | last post by:
Hi, I've found what appears to be a bug with ASP.NET web service method invocation - making it impossible to invoke and get the result of a synchronous web call after an asynchronous call has been made if both are using sessions. Heres an example for two calls in the web service, the first is expected to be executed asynchronously by the client and the second to get the progress of the first while it is executing:
0
10139
by: mammucion | last post by:
Trying to automate processing 80,000 data sets through 15 web pages. Application URL creates a new IE instance in which runs first a login form and then runs the rest of the pages in the new window. I can connect to a running Excel instance and obtain information from the Excel DOM. I cannot do the same with Internet Explorer. However, I can successfully create an new IE instance and manipulate it. Using an application that has its own...
9
1894
by: JoeB | last post by:
Hi, This is 100% reproducable. .NetCF / WinCE5.0 / VS.Net 2003 1. Create a new 'smart device application' project. 2. Add a progress bar to the form 'progressBar1' 3..Add: using System.Threading; to the top of the code.
13
28734
by: Sandeep Singh | last post by:
I am making socket client application in C# how can i get ip address of client who has connected to server
11
4332
by: Olie | last post by:
This post is realy to get some opinions on the best way of getting fast comunication between multiple applications. I have scowered the web for imformation on this subject and have just found conflicting views and far from ideal solutions. My application has to send small amounts of data about 50bytes to multiple client applications. The catch is that this has to happen about 1000 times a second. My first attempt was .net remotting...
3
1136
by: Richard MSL | last post by:
I have a C# application that works, with a main menu where the user can choose different options that run, and then return to the menu. I want to change it so that the user can starting running an option, then initiate another menu option, so that both are running at the same time, independently. As each one finished, that thread would end and the main menu would remain. Right now my code is like this: while(true){...
12
2287
by: Justin | last post by:
I can attach my code if anyone wants to see it however I'll try to ask my question with some mark up code first. I'm having a problem terminating my process while using DoEvents. For example: Button.text = start If button.text = start then button.text = stop
3
7263
by: Marco Shaw | last post by:
C# novice... Can I create a console application (think the Pine email reader or even 'edit' in DOS) where I can use my up/down/side arrows to move around the app? I'd want something with a simple menu system as well as popup functionality. Any hints/pointers to get me started?
10
3049
by: Jason (Kusanagihk) | last post by:
To all, I have written a SerialPort class / application using C# and .Net Framework 3.0. but I have a question; since my serialPort class / application is not a Windows Form application (rather it is just a console program); therefore I need a way to make the application "alive" until I kill the application or enter a "quit" signal through the serial port. I have tried the simplest way to make the app "alive" by using a
0
8265
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
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
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
8364
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
7193
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
6125
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
5574
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
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
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.