When using threads I've read in plenty of places that you are not to modify UI Controls from inside worker threads and they usualy go on to say that you should use invoke to make any changes.
If I create a class and the worker thread started is given a method within that class that contains events that can be called is that the same thing or at least another way of accomplishing the same thing.
For example this psuedo code example...
I think this is ok since the whole point of using invoke is that the modification of the UI happens on the UI thread and thats what this accomplishes. Is this correct?
If I create a class and the worker thread started is given a method within that class that contains events that can be called is that the same thing or at least another way of accomplishing the same thing.
For example this psuedo code example...
Code:
class myClass
{
public myClass()
{
}
//
public void WorkerMethod()
{
//Do Something
EventArgs e = new EventArgs();
OnSomeException(e);
}
public delegate void SomeErrorEventHandler(EventArgs e);
public event SomeErrorEventHandler SomeException;
protected virtual void OnSomeException(EventArgs e)
{
if(SomeException != null)
{
SomeException(e);
}
}
}
myClass myC = new myClass() //class declaration
void main()
{
myC.SomeException += SomeErrorEventHandler(EventArgs e);
Thread myThread = new Thread(newThreadStart(myC.WorkerMethod()));
myThread.Start();
}
//declare a function that will handle the SomeErrorEventHander
//and modify the user interface
I think this is ok since the whole point of using invoke is that the modification of the UI happens on the UI thread and thats what this accomplishes. Is this correct?