-2

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 ?

user1863359
  • 317
  • 1
  • 10
  • 23

3 Answers3

3

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.

Community
  • 1
  • 1
SchautDollar
  • 348
  • 3
  • 13
0

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.

Adriaan Stander
  • 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
0

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.

Rob Goodwin
  • 2,676
  • 2
  • 27
  • 47