473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

While(true)Application.DoEvents 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.DoEvents()
}

it works, while if I do this:

while(true)
{
FormFinder finder = new FormFinder();
FormCollection theForms = finder.FindAll("Employee Transfers");
if(theForms.Count > 0) break;
Application.DoEvents()
}

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 4736
<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.DoEvents()
}

it works, while if I do this:

while(true)
{
FormFinder finder = new FormFinder();
FormCollection theForms = finder.FindAll("Employee Transfers");
if(theForms.Count > 0) break;
Application.DoEvents()
}

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.DoEvents 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.com>
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.com>
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.DoEvents 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*********************@z14g2000cwz.googlegro ups.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.DoEvents 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(OtherMethod));
thread.Start();
Application.Run()
}

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

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 PreProcessMessage 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.googlegr oups.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.DoEvents 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(OtherMethod));
thread.Start();
Application.Run()
}

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

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
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...
0
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...
0
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...
9
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...
13
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
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...
3
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...
12
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: ...
3
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...
10
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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,...
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...

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.