Click here to Skip to main content
15,861,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi every one,

I'm working on a windows form application, I want to change the the image of a picture box from a class outside the form, but the problem is that they are running on two different threads. I know I should use a delegate in order to handle the application just under one thread. but I couldn't succeed to do that.
Posted

Hi,

Try:
C#
yourForm.Invoke((MethodInvoker)delegate
            {
                // your code here
            });

I use an anonymous method, but because the Invoke method requires a System.Delegate, I cast it to a MethodInvoker (a delegate):
http://msdn.microsoft.com/en-us/library/system.windows.forms.methodinvoker.aspx[^]

Hope this helps.
 
Share this answer
 
v2
Comments
Behno0o0oD 9-Jul-13 5:18am    
Thanks,
but what is MethodInvoker?
Could you please explain more?
Thomas Daniels 9-Jul-13 5:22am    
I updated my answer.
Behno0o0oD 9-Jul-13 5:23am    
Thanks,
It works :)
Many Thanks
Thomas Daniels 9-Jul-13 5:35am    
You're welcome!
C#
if (pictureBox1.InvokeRequired)
{
    this.Invoke(new Delegate(Method));
}
 
Share this answer
 

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