Z
Zürcher See
I'm using the following structure for my programm, and I never had problems.
Now by the invoke of the MyObject_End eventhandler I get the following
error:
System.Windows.FormsSpecified cast is not valid.
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate
method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
....
What's wrong with it now? Cast of what?
Thank's
Program structure:
class Main
{
protected EventHandler myObjectEnd;
public Main()
{
this.myObjectEnd=new EvenrHandler(this.MyObject_end);
...
}
protected void StartNewMyObject()
{
...
MyObject myObject=new MyObject();
myObject.End+=this.myObjectEnd;
System.Threading.ThreadPool.QueueUserWorkItem(new
System.Threading.WaitCallback(myObject.Start));
...
}
protected void MyObjectEnd(MyObject myObject)
{
//Handle the MyObject End event
...
}
private void MyObject_End(object sender, EventArgs e)
{
if (this.InvokeRequired) this.Invoke(this.myObjectEnd,new
object[]{sender,e});
else this.MyObjectEnd((MyObject)sender);
}
}
class MyObject
{
public event EventHandler End;
protected void OnEnd() {if (this.End!=null) this.End(this,new
EventArgs());}
public void Start()
{
...
this.OnEnd();
}
}
Now by the invoke of the MyObject_End eventhandler I get the following
error:
System.Windows.FormsSpecified cast is not valid.
at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate
method, Object[] args, Boolean synchronous)
at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
....
What's wrong with it now? Cast of what?
Thank's
Program structure:
class Main
{
protected EventHandler myObjectEnd;
public Main()
{
this.myObjectEnd=new EvenrHandler(this.MyObject_end);
...
}
protected void StartNewMyObject()
{
...
MyObject myObject=new MyObject();
myObject.End+=this.myObjectEnd;
System.Threading.ThreadPool.QueueUserWorkItem(new
System.Threading.WaitCallback(myObject.Start));
...
}
protected void MyObjectEnd(MyObject myObject)
{
//Handle the MyObject End event
...
}
private void MyObject_End(object sender, EventArgs e)
{
if (this.InvokeRequired) this.Invoke(this.myObjectEnd,new
object[]{sender,e});
else this.MyObjectEnd((MyObject)sender);
}
}
class MyObject
{
public event EventHandler End;
protected void OnEnd() {if (this.End!=null) this.End(this,new
EventArgs());}
public void Start()
{
...
this.OnEnd();
}
}