Hi all,
Here is my problem, I have a class which have a object who throw an event and in this event I throw a custom event from my class. But unfortunately the original object throw the event from another thread and so my event is also throw on another thread. This cause a exception when my custom event try to access from controls.
Here is a code sample to better understand :
class MyClass
{
// Original object
private OriginalObject myObject;
// My event
public delegate void StatsUpdatedDelegate(object sender, StatsArgs args);
public event StatsUpdatedDelegate StatsUpdated;
public MyClass()
{
// Original object event
myObject.DoSomeWork();
myObject.AnEvent += new EventHandler(myObject_AnEvent);
}
// This event is called on another thread while myObject is doing his work
private void myObject_AnEvent(object sender, EventArgs e)
{
// Throw my custom event here
StatsArgs args = new StatsArgs(..........);
StatsUpdated(this, args);
}
}
So when on my windows form I call try to update a control from the event StatsUpdated I get a cross thread exception cause it has been called on another thread.
What I want to do is throw my custom event on the original class thread, so control can be used within it.
Anyone can help me ?