473,386 Members | 1,602 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,386 software developers and data experts.

How process messages in a loop?

I am copying data from one FileStream to another in a loop. Inside the
loop I display progress messages in a StatusBar. The form has a Stop
button that sets a private Boolean variable to true. Also inside the
loop I check that value of the variable and exit the loop if it is true.

I have two problems. First, clicking the Stop button has no effect.
It's Click event handler does not execute. Second, if I drag the form
to a different location on the screen the progress messages stop
displaying even though I call StatusBar.Refresh in the loop.

What should I call in the loop to allow messages and events to be
processed?

--
..Bill.
Nov 17 '05 #1
3 1945
Bill <no@no.com> wrote:
I am copying data from one FileStream to another in a loop. Inside the
loop I display progress messages in a StatusBar. The form has a Stop
button that sets a private Boolean variable to true. Also inside the
loop I check that value of the variable and exit the loop if it is true.

I have two problems. First, clicking the Stop button has no effect.
It's Click event handler does not execute. Second, if I drag the form
to a different location on the screen the progress messages stop
displaying even though I call StatusBar.Refresh in the loop.

What should I call in the loop to allow messages and events to be
processed?


You shouldn't. Instead, you should do the processing in a different
thread, crossing back to the UI thread to update the UI with progress.

See http://www.pobox.com/~skeet/csharp/t...winforms.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
Hi Bill,

As Jon said, you should use another thread for processing and keep the UI thread free. However, there is a way that will accomplish what you seek (for short tiny applications :). Calling Application.DoEvents() will process pending events.
On Sun, 24 Jul 2005 22:49:47 +0200, Bill <no@no.com> wrote:
I am copying data from one FileStream to another in a loop. Inside the
loop I display progress messages in a StatusBar. The form has a Stop
button that sets a private Boolean variable to true. Also inside the
loop I check that value of the variable and exit the loop if it is true.

I have two problems. First, clicking the Stop button has no effect.
It's Click event handler does not execute. Second, if I drag the form
to a different location on the screen the progress messages stop
displaying even though I call StatusBar.Refresh in the loop.

What should I call in the loop to allow messages and events to be
processed?


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #3
Thanks guys. Application.DoEvents will solve my immidiate problem. I
will rewrite this using threads since I need to learn how to use
threads anyway.

--
..Bill.
Nov 17 '05 #4

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

Similar topics

1
by: jenny | last post by:
Hi, I have a java socket program running on AIX 4.3.3.0 platform. It opens a socket and sends data to our customer over a leased fractional T1 line. The line is always connected. However,...
12
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
77
by: Charles Law | last post by:
Hi guys I have a time critical process, running on a worker thread. By "time critical", I mean that certain parts of the process must be completed in a specific time frame. The time when the...
0
by: Jason Ferree | last post by:
I posetd this in one group, but got no response, so I'll try it in this one. I am trying to loop through all messages in the inbox. To do something, in my case, look for and save attachments....
5
by: GTS | last post by:
Hi All, I am spawning a process from a service. The spawned process hungs for various reasons, (corrupted data, deadlock). I am expecting the process has to complete the task with in the...
2
by: Derek Martin | last post by:
Howdy folks, I have a sleeping thread that runs every 20 seconds or so to check for messages from a database message store. When it detects an un-acknowledged message, I am firing off a...
0
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a C# application in which I start another process which produces output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++ compiler itself! I would like to...
32
by: John Wright | last post by:
I have a long process I run that needs to be complete before the user can continue. I can change the cursor to an hourglass, but I want to update the Status Strip on the bottom during the process. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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.