I have a small application coded on c# (Windows Form)(visual stud 2012) when I run the application it work properly except that when the application is running i can't no more click on the window or even move it, until it finish the process how can I solve this problem ?
-
2Move the work to a separate thread. Search here for `[c#] Background worker`. – Ken White Jun 20 '13 at 15:57
-
So the thread is busy. Hmm. Could you share the code you are using that is taking up the thread? Maybe we can give some pointers. – SchautDollar Jun 20 '13 at 15:58
3 Answers
You could implement the BackgroundWorker Control/Class.
To do this, just drag the control BackgroundWorker
from the toolbox on to the form. Select the background worker you just created and double-click on it. Now put all the code you need to do separately from the UI into this event.
Example:
//Assuming we have a background worker called backgroundWorker
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
//put code here
}
Now in the triggering block of code, call backgroundWorker.RunWorkerAsync()
.
Example:
private buttonDoWork_Click(object sender, EventArgs e) {
backgroundWorker.RunWorkerAsync();
}
Just be careful and be threadsafe.

- 1
- 1

- 348
- 3
- 13
-
woooow !!! it's fixed now :D Thank you i will try to make the same thing to fix the progress bar update – user1863359 Jun 20 '13 at 16:45
Have a look at using BackgroundWorker Class
Executes an operation on a separate thread.
The BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running. When you want a responsive UI and you are faced with long delays associated with such operations, the BackgroundWorker class provides a convenient solution.

- 162,879
- 31
- 289
- 284
-
Threads again :( i'm not so good on the thread things, but i will try to have an idea about it (i was trying to make a progress bar with a thread but finally i let it down) – user1863359 Jun 20 '13 at 16:00
-
I don't know how to put my code on the : private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) {} because the method that take a lot of time is called when the user click on a button public partial class Welcome : Form { private BackgroundWorker backgroundWorker1; public Welcome() { } private void Button3Click(object sender, EventArgs e) { //call a method that take a lot of time } } – user1863359 Jun 20 '13 at 16:32
Sounds like you are doing your processing on the UI Thread. Any processing you do on the UI thread takes away cycles that User Interface events can be serviced.

- 2,676
- 2
- 27
- 47