Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to call a function present on the Main form from another class which includes threads so i am using Control.Invoke Method But this hangs my main Form in the middle. Can Anyone provide me an alternative.


This is the way i call that function.
ThreadTermination is the delegate declared on the main form.

frm.Invoke(frm.ThreadTermination, this);


Thanks
Posted

Well, for a start I wouldn't be directly invoking a method on that form. When I've wanted to notify the parent form that something needs to be done, or that something has happened, I normally have an event in my child form which the parent form subscribes to. Then all you need to do is raise the event to have it handled by the parent form.
 
Share this answer
 
Comments
Member 4354249 18-May-12 6:28am    
can you provide me some code related to that if possible:)
Did you try
frm.BeginInvoke(frm.ThreadTermination, this);
 
Share this answer
 
Comments
Member 4354249 18-May-12 6:27am    
yeah.. but the problem is i want to block the caller so that it shouldnt take other request till i complete the execution of called fuction.
Maybe you should try:

Dispatcher.CurrentDispatcher.Invoke(frm.ThreadTermination, this);
 
Share this answer
 
Comments
Member 4354249 21-May-12 2:52am    
using Dispatcher class the function is execute by the worker thread itself not the main thread.
[no name] 21-May-12 12:47pm    
I also think that solution 1 is the best way to go. (Using events)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900