Solved

UI window threading and delegates

Posted on 2003-11-14
7
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

635 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