Click here to Skip to main content
14,356,080 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,

Try:
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.
   
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!
Rate this:
Please Sign up or sign in to vote.

Solution 2

if (pictureBox1.InvokeRequired)
{
    this.Invoke(new Delegate(Method));
}
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100