Zygis

Zygis

  • NA
  • 14
  • 13.8k

Help with using .Invoke()

May 17 2011 8:28 AM
Hello again,

Here's the thing: I get an error "Cross-thread operation not valid: Control 'pictureBox1' accessed from a thread other than the thread it was created on.";

Here's the situation: I start System.Timers.Timer in Class33(Form), when the timer elapses it calls a method which makes another class - Class1(Not a Form, just a class). When Class1 code is being executed it "wants" to change picture on the Class33(Form) and then i get that error.

Here's what i found:
        1) i could use Control.CheckForIllegalCrossThreadCalls, but it's not very good choice;
        2) I should use .Invoke() method which is good;

Here's the problem: I don't understand how to use it. What should I invoke: Class33 or Class1 or something else...?

Hope you have understood my problem, thank you.

Answers (4)