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.
Loading
Sam HobbsPosted May 17, 2011, 7:31 PM
Microsoft has attempted to make it simple using the Control.InvokeRequired Property. You can search this web site's articles and forums for help with that. For example Accessing Windows Forms Controls across Threads and Updating the UI on different thread.
VulpesPosted May 17, 2011, 10:37 AM
ZygisPosted May 17, 2011, 10:14 AM
1) why in Class1 "class33.pictureBox1.Visible = false;" needs to be invoked, but later code "class33.pictureBox1.Image = b;" doesnt need to be invoked? Is the .Invoke() method invoked whole pictureBox1 so it doesnt need to be invoked later?
2) should I end that invoking proccess somehow or does end as soon as I dispose class1?
3) maybe it is better to use BeginInvoke instead?
VulpesPosted May 17, 2011, 9:18 AM