Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

UI window threading and delegates

I have a windows app which can open different Mdi Child forms. Each form may do extensive processing but I do not want them to freeze up the main form preventing me from doing other things.
I am using the following code to attempt to run this processing in its own thread:

private void btn_processSource_Click(object sender, System.EventArgs e) {

GenerateReportDelegate genReport=new GenerateReportDelegate(generateReport);
BeginInvoke(generateReport, null); //where generateReport does much processing.

}

This does not allow me to anything in the main form until processing 'generateReport' is done.

I have also tried the following:


private void btn_processSource_Click(object sender, System.EventArgs e) {

GenerateReportDelegate genReport=new GenerateReportDelegate(generateReport);
genReport.BeginInvoke(null, null);

}

This seems to provide the asynch call and allow me to do other things on the main form but never never refreshes when generateReport is finished, thus hanging in neverland.

Any ideas??
0
ipaman
Asked:
ipaman
  • 4
  • 3
1 Solution
 
ptmcompCommented:
To change the form/controls or call any method on the form you need to synchronize the calls over myForm.Invoke or myControl.Invoke.
E.g. you can change to MouseCursor to AppStarting while the background process and set it back to default afterwards.
0
 
ipamanAuthor Commented:
What is the code look like to synchronize these calls?
0
 
ptmcompCommented:
Sorry, I didn't leave a comment anymore cause I was very busy. Did you figure it out?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ipamanAuthor Commented:
No, not completely.
0
 
ptmcompCommented:
So, how far did you get it? It's easier for me to help you when I know what you understood/misunderstood than trying to explain it from scratch, cause I don't know at what level I have to start my explanation.
0
 
ipamanAuthor Commented:
ptmcomp,

My original question is sort of a good starting point. The only thing I can add simply is that (with the above example) the thread does not return to the calling form. I want to be able to (in a Form) kick off a threat and still be able to click and launch other forms while the form with the worker thread is still running.

Hope that is enough,
ipaman
0
 
ptmcompCommented:
I'll make a sample project but at the moment I don't have a lot of time. I'll also check if somone posted already a sample on www.codeproject.com
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now