473,327 Members | 1,936 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,327 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 4733
<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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.