Solved

UI window threading and delegates

Posted on 2003-11-14
7
317 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

15 Experts available now in Live!

Get 1:1 Help Now