Solved

UI window threading and delegates

Posted on 2003-11-14
7
322 Views
Last Modified: 2010-05-18
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
Comment
Question by:ipaman
  • 4
  • 3
7 Comments
 
LVL 10

Accepted Solution

by:
ptmcomp earned 125 total points
ID: 9754437
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
 

Author Comment

by:ipaman
ID: 11538579
What is the code look like to synchronize these calls?
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 11865657
Sorry, I didn't leave a comment anymore cause I was very busy. Did you figure it out?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:ipaman
ID: 11880607
No, not completely.
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 11885609
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
 

Author Comment

by:ipaman
ID: 11887099
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
 
LVL 10

Expert Comment

by:ptmcomp
ID: 11896315
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now