473,857 Members | 1,841 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 4766
<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
1677
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
10177
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
1903
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
28799
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
4354
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
1148
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
2306
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
7276
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
3065
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
9768
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
10711
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
10808
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
10394
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
7104
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
5774
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...
1
4592
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
2
4191
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.