473,406 Members | 2,281 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,406 software developers and data experts.

Windows Forms - stop form looking like it has crashed whilst routine running

Ben
Hi

We have a windows form that takes a while to run a routine.

During this we have created a information label, updating the user on the
progress but:

a) The changes on the label are not visible until the routine has finished
b) If the form looses focus it appears to the user that it has crashed

Is there any way to stop the above from happening?

Thanks
B
Jan 4 '07 #1
3 1772
Hi Ben,

the only way to keep your form responsive is to run the time consuming
code in a different thread. If you're using .NET Framework 2.0 and
Visual Studio 2005 you can use a new component called
"BackgroundWorker", which makes the handling of an additional thread
much easier. Please refer to the online help by searching for
BackgroundWorker. One important hint: don't try to update any form
controls in the event handler for the DoWork-Event because winform
controls can only be updated by the thread that created them, use the
ProgressChanged-Event instead.

cya
Axel

Ben a écrit :
Hi

We have a windows form that takes a while to run a routine.

During this we have created a information label, updating the user on the
progress but:

a) The changes on the label are not visible until the routine has finished
b) If the form looses focus it appears to the user that it has crashed

Is there any way to stop the above from happening?

Thanks
B
Jan 4 '07 #2
Ben wrote:
Is there any way to stop the above from happening?
The "best" route is almost certainly to run the time-consuming routine in
another thread, as has already been suggested.

However an easier solution that may well still accomplish your goal is to
get the window to repaint itself from time to time.

At regular intervals within your code you can either force the form to
refresh itself:

\\\
Me.Refresh()
///

(assuming the code is running within a procedure within the form itself) or
alternatively allow the application to process all queued events:

\\\
Application.DoEvents()
///

The Refresh method will cause all visual elements of the form to be updated.
This will get your label text update fixed and will get the window to
repaint if other windows have obscured it. You won't be able to interact
with the window however until the routine has finished, as the events will
be queued but temporarily ignored. Once the procedure is finished, all the
queued events will be processed together.

The DoEvents method will allow the screen to repaint and the label to be
updated, and will also process any events that have been queued. This will
allow the user to, for example, move or close the window, click buttons and
interact with other UI elements.

Have a go with these and see if they do what you want.

--

(O)enone
Jan 4 '07 #3
Ben
Thank you both for your posts. I will use Refresh Now and will consider
multithreading in the future.

Thanks
B
"(O)enone" <oe****@nowhere.comwrote in message
news:Gn******************@newsfe5-win.ntli.net...
Ben wrote:
>Is there any way to stop the above from happening?

The "best" route is almost certainly to run the time-consuming routine in
another thread, as has already been suggested.

However an easier solution that may well still accomplish your goal is to
get the window to repaint itself from time to time.

At regular intervals within your code you can either force the form to
refresh itself:

\\\
Me.Refresh()
///

(assuming the code is running within a procedure within the form itself)
or alternatively allow the application to process all queued events:

\\\
Application.DoEvents()
///

The Refresh method will cause all visual elements of the form to be
updated. This will get your label text update fixed and will get the
window to repaint if other windows have obscured it. You won't be able to
interact with the window however until the routine has finished, as the
events will be queued but temporarily ignored. Once the procedure is
finished, all the queued events will be processed together.

The DoEvents method will allow the screen to repaint and the label to be
updated, and will also process any events that have been queued. This will
allow the user to, for example, move or close the window, click buttons
and interact with other UI elements.

Have a go with these and see if they do what you want.

--

(O)enone

Jan 5 '07 #4

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

Similar topics

0
by: Simon Verona | last post by:
I know this is a little of topic, for which I apologise, but I think it's pertinent to .Net development so I hope it's ok to ask this question here! I'm looking to created filled in "forms" from...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
0
by: Frans Bouma | last post by:
Hello, It seems VS.NET 2003 locks up itself and the complete shell (mouse locks also) when entering a breakpoint in a special situation. Below is the code to reproduce this behavior. It...
3
by: belgiozen | last post by:
Hi, I have a working windows service,it is looking for files on the disk and when some of the files are cupdated it calls an executable. But it takes a lot of time(about 10 minutes) to run the...
6
by: billr | last post by:
I have developed a small API for taking care of a lot of boiler plate stuff in a multi formed windows application, for example setting up a messaging thread framework. New Forms, in the...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
1
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
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: 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: 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
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...
0
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...
0
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,...
0
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...

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.