S
Sin Jeong-hun
Hi.
I want to raise an event in the worker thread to let the UI display
the status, but I do not block the operation itself. The following
codes are just to illustrate the situation, not the real codes.
class Logic
{
public MyEventHandler MyEvent;
public void Start()
{
Thread t = new Thread(new ThreadStart(Work));
t.Start();
}
void Work()
{
while(true)
{
Process one item
MyEvent(this, number of items processed); <---- Line A
}
}
}
class Consumer
{
void Consumer
{
Logic l = new Logic();
l.MyEvent += new MyEventHandler(DoSomeCalc);
}
void DoSomeCalc(....)
{
doing lengthy stupid operations....
}
}
The Work() thread seems to be blocked at Line A if the event consumer
does not return soon. If I am the writer of the UI and it's a Windows
Form, I could use Form's BeginInvoke so that it return will soon, but
I want to make the Line A would work like so no matter how the event
consumer is coded. Was my explination enough? Basically, I just want
to signal others with MyEvent then continue to loop, not to be blocked
by the event consumer at Line A.
What is the best practice for this case? Thanks for any advice.
I want to raise an event in the worker thread to let the UI display
the status, but I do not block the operation itself. The following
codes are just to illustrate the situation, not the real codes.
class Logic
{
public MyEventHandler MyEvent;
public void Start()
{
Thread t = new Thread(new ThreadStart(Work));
t.Start();
}
void Work()
{
while(true)
{
Process one item
MyEvent(this, number of items processed); <---- Line A
}
}
}
class Consumer
{
void Consumer
{
Logic l = new Logic();
l.MyEvent += new MyEventHandler(DoSomeCalc);
}
void DoSomeCalc(....)
{
doing lengthy stupid operations....
}
}
The Work() thread seems to be blocked at Line A if the event consumer
does not return soon. If I am the writer of the UI and it's a Windows
Form, I could use Form's BeginInvoke so that it return will soon, but
I want to make the Line A would work like so no matter how the event
consumer is coded. Was my explination enough? Basically, I just want
to signal others with MyEvent then continue to loop, not to be blocked
by the event consumer at Line A.
What is the best practice for this case? Thanks for any advice.