Hi,
I have a win form application, when a button is clicked, a lengthy
operation will be triggered. During the time program is still running, this
application seems not to be able to response to other actions. When I switch
to other window, and switch back to my application, all I can see is a white
window, it won't refresh itself until operation finishes.
If I have some other buttons in the form, it is not possible to show up
during operation. What is the way I can let my operation to run, but
meanwhile application can accept other GUI events?
Thanks
Hardy 4 1951
Hardy Wang wrote: Hi, I have a win form application, when a button is clicked, a lengthy operation will be triggered. During the time program is still running, this application seems not to be able to response to other actions. When I switch to other window, and switch back to my application, all I can see is a white window, it won't refresh itself until operation finishes. If I have some other buttons in the form, it is not possible to show up during operation. What is the way I can let my operation to run, but meanwhile application can accept other GUI events?
Thanks Hardy
If you're application is written completely in .NET, consider executing
your operation in a thread. It's fairly simple to do, but you'll have
to put in some extra code to disable the button (unless you want
multiple threads of the same operation running).
Here's the MSDN docs on System.Threading: http://msdn.microsoft.com/library/de...mthreading.asp
All you need is a function to create a thread, so I'd wrap whatever that
operation is within a function.
If your lengthy operation is not .NET, try executing it as an external
process, and not using P/Invoke to make a DLL call. You might be able
to wrap the P/Invoke call in a thread too, but I'm unsure of that.
In article <uS**************@TK2MSFTNGP09.phx.gbl>, ha*******@hotmail.com says... Hi, I have a win form application, when a button is clicked, a lengthy operation will be triggered. During the time program is still running, this application seems not to be able to response to other actions. When I switch to other window, and switch back to my application, all I can see is a white window, it won't refresh itself until operation finishes. If I have some other buttons in the form, it is not possible to show up during operation. What is the way I can let my operation to run, but meanwhile application can accept other GUI events?
You'll need to start up another thread to run your code on. Basically,
windows forms start with a single thread which contains the message pump
(the OS is sending all of the windows messages to your app -- paint,
mouse clicks, key clicks, etc...) If your app is busy doing a long-
running process, it won't be able to respond to those events (like
paint) and your UI will suffer.
Look into threading and also be mindful of updating the UI from a
background thread (need to use Control.Invoke for this).
--
Patrick Steele
Microsoft .NET MVP http://weblogs.asp.net/psteele
Thanks, I got it. It works fine for me with a new thread.
"Mike Newton" <MN*****@Addus.com> wrote in message
news:ON**************@TK2MSFTNGP09.phx.gbl... Hardy Wang wrote:
Hi, I have a win form application, when a button is clicked, a lengthy operation will be triggered. During the time program is still running,
this application seems not to be able to response to other actions. When I
switch to other window, and switch back to my application, all I can see is a
white window, it won't refresh itself until operation finishes. If I have some other buttons in the form, it is not possible to show
up during operation. What is the way I can let my operation to run, but meanwhile application can accept other GUI events?
Thanks Hardy
If you're application is written completely in .NET, consider executing your operation in a thread. It's fairly simple to do, but you'll have to put in some extra code to disable the button (unless you want multiple threads of the same operation running).
Here's the MSDN docs on System.Threading: http://msdn.microsoft.com/library/de...mthreading.asp All you need is a function to create a thread, so I'd wrap whatever that operation is within a function.
If your lengthy operation is not .NET, try executing it as an external process, and not using P/Invoke to make a DLL call. You might be able to wrap the P/Invoke call in a thread too, but I'm unsure of that.
Hardy Wang <ha*******@hotmail.com> wrote: I have a win form application, when a button is clicked, a lengthy operation will be triggered. During the time program is still running, this application seems not to be able to response to other actions. When I switch to other window, and switch back to my application, all I can see is a white window, it won't refresh itself until operation finishes. If I have some other buttons in the form, it is not possible to show up during operation. What is the way I can let my operation to run, but meanwhile application can accept other GUI events?
See http://www.pobox.com/~skeet/csharp/multithreading.html
and in particular http://www.pobox.com/~skeet/csharp/m...#windows.forms
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Matt |
last post by:
(can't find any of my previous post for same issue. please CC to my email
address as well. Thanks!)
Hi all,
What is the possible reason that HttpWebRequest.GetRequestStream() may hang
there...
|
by: Ken Varn |
last post by:
I have an ASP.NET form that may take a very long time to process a
particular request. If the user closes the browser window, the request will
continue to process until it completes. This is a...
|
by: Tom |
last post by:
I have a VB.NET framework 1.1 application that I am installing on my user's
workstation. It works fine on EVERY machine except for one - on this one
machine it generates a 'Overflow or underflow in...
|
by: Cerebrus99 |
last post by:
Hi all,
I'm making a Windows application that does some lengthy retrieval operations
from a database and possibly from a internet resource.
I want to show that the operation is going on, by...
|
by: Jonah Bishop |
last post by:
I'm developing a photo album web application for use on a web site, and
I'm running into a problem with lengthy operations. My application
allows the user to import a number of images at once into...
|
by: michael sorens |
last post by:
I have a lengthy sequence of operations that are executed and reported on
in a status window in a Windows Form application. Some work is done by
background threads but other work is not. I am...
|
by: nospam |
last post by:
Hi all.
I have encountered a "Cross-thread operation not valid" error in a
test program I created and although I have came up with a solution I
don't like the performance of the program.
I...
|
by: Dmitry Teslenko |
last post by:
Hello!
I'm using os.popen to perform lengthy operation such as building some
project from source.
It looks like this:
def execute_and_save_output( command, out_file, err_file):
import os
...
|
by: arvinds |
last post by:
I have an application in which I have 2 forms.
1.Review Form 2. FilmForm.
Review Form is used for Loading some images and we can transfer the
Images from Review From to FilmForm by Drag-Drop...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: 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...
| |