Solved

UI window threading and delegates

Posted on 2003-11-14
7
320 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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