Dear all,

I am having a very frustrating problem with a project in Visual Studio 2008 C#. I have tried everything, I have searched everywhere, but it seems that nothing works. I would appreciate if someone gave me some directions or suggestions, as to where to look for the solution.
What I want to do:
I have 2 forms. The MAIN form, runs a heavy image processing algorithm, using a background worker. The second form, FORM2 must have a progress bar, which will display the progress of the image processing executed in MAIN form. It must also have a CANCEL button, which will allow the canceling of the image processing algorithm.

What I have done so far:
1. I have managed to solve the problem using only one form: there is no FORM2. The progress bar and the cancel button are on the MAIN form. Everything works fine. But this is not the thing I have to do! I really need the cancel button and the progress bar on a different form.
2. I have managed to show the progress bar on FORM2 running smoothly, but I cannot interact with FORM2 (the mouse pointer becomes a hourglass when I hover it over FORM2, thus, I cannot press the CANCEL or the X button).
In order to do that, I wrote the following code:

In MAIN form:

FORM2 PR = new FORM2();
for (i = 0; i < imsize_y; i++)
      //calculate the progress degree and store it in ‘Process’ variable

      PR.progressBar1.Value = Process;
      PR.Refresh(); //otherwise the PR form is not redrawn

      if (backgroundWorker1.CancellationPending   
              PR.Close();//where the code stops in case cancel is pressed

      for (j = 0; j < imsize_x; j++)
		//heavy image processing



3. I have also tried to use


instead of


,in order have focus on FORM2. However, in this case, the image processing stops until and I have to press something in FORM2 in order to proceed with the image processing in MAIN form.

I know that this has to do something with threading, but I don’t know what. When the MAIN form runs, I cannot interact with FORM2. I have found examples where I can communicate variables between forms, but, in these examples, there is no background worker involved.

I would appreciate any suggestions or directions, as to where to look for this solution.


I think you should make an asnychronous call off your main thread, so it can work on the image processing in the background and leaving the main thread lag free, so the user can interact with it. I know it's not an easy task and especially for the first try, but please keep trying first and ask with specific questions if something is wrong, there's no point for posting the entire solution and just use that without any further care.

Start with a tutorial like this : and try to adapt it to your needs.

Good luck :)