473,804 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1794
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
"BackgroundWork er", which makes the handling of an additional thread
much easier. Please refer to the online help by searching for
BackgroundWorke r. 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.DoE vents()
///

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******** **********@news fe5-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.DoE vents()
///

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
1411
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 my application eg Sales Orders, Quotations etc which have data filled in from my application. I want my users to be able to design their own form templates (eg to include their company logos, terms and conditions etc). The standard .Net...
19
4115
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 the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
0
2414
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 contains a line where you have to set a breakpoint (the first line in the validation event handler). Compile and run in the debugger in vs.net using F5. When you hit 'enter' in the textbox, the debugger should break in the validator routine where you...
3
5145
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 executable.So while that executable is running,if I try to stop the windows service while the executable(MYPROGRAM.EXE) is running,it will wait for a time(about 20 seconds) for the main windows thread to abort.If it does not finish its work, the...
6
2643
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 appllication using the API, are subclassed to a Form contained within the API, and they are controlled (controlled in this instance means, kept alive, displayed and hidden) at runtime by a thread whose responsibility is this sole task. In order to run...
1
3456
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 going wrong. The program has been written to do the following tasks: - Select remote server - Select from two specific services
0
3945
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 - Select from two specific services - Check the status of the server
1
650
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 objective in utilizing this new deployment method is to reduce the maintenance overhead as well as making it easier for my users to setup and run the application initially. I have VS 2002, Windows XP, Access XP(2000 format). He is my problem....
4
4186
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 check to see if the status is in stopped or running mode. But that doesn't tell me if it is actually running. I need to know this so that if it happens I can programmatically start the same service on another machine.
0
9714
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10346
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
10347
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
10090
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
9173
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5531
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...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4308
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
3
3001
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.