Hi,
I create a class whitch creates a thread. When thread finish it has to fire
event. But I want to fire this event in the context of the thread that
created the class (usually main thread). For this I create a control in
context of the creator thread. But are there better techniques,like maybe
create a hidden window or something else ? this is code snippets i use now:
public class CDelay
{
Control Ctrl;
public delegate void RequestDone(object sender, RequestDoneArgs e);
public event RequestDone OnRequestDone;
public class RequestDoneArgs: EventArgs
{
Int32 FThreadId;
public RequestDoneArgs(Int32 ThreadId)
{
FThreadId = ThreadId;
}
public Int32 ThreadId
{
get { return FThreadId; }
}
}
public CDelay(Control Parent)
{
Ctrl = new Control();
Ctrl.Parent = Parent;
So in constructor Ctrl is created in thread context of the creator (Parent).
When I have to call event I use the normal Invokething:
RequestDoneArgs e = new
RequestDoneArgs(Thread.CurrentThread.ManagedThread Id);
if(OnRequestDone != null)
Ctrl.BeginInvoke(OnRequestDone, new object[] { this, e });
It works as a glance, but if there are better things ZI like to know of
course.
--
rgds, Wilfried
http://www.mestdagh.biz