M
MIke Brown
Hello all,
I've been searching for a solution on google for a problem related to
creating events from a worker thread, with no luck..
Basically, the problem is when my events are caught by a UI using my
class, they get the usual "Control 'blah' accessed from a thread other
than the thread it was created on.". I understand that of course, but
my class is to be distributed to people who don't want to have to worry
about invoking delegates in the event handler, I want to keep it all
neat and tidy inside the class and they can do whatever they want in
the events I throw. Is there a way to launch my event on the thread the
class was created on, instead of my worker thread? I've tried using a
delegate thinking that would work, but it doesn't. I've also tried
inheriting from Control and using Invoke, which doesn't seem to work as
well.
Is there something I'm missing to easily accomplish this within my
class?
<?
.....
public myclass()
{
readThread = new Thread(new ThreadStart(ThreadLoop));
}
public void ThreadLoop()
{
while(some waithandle)
{
if(something)
if(myevent!=null) myevent(this, new args(1,2,3,4));
// instead of calling the above event here, I need to trigger
something
// in the thread the class was created on (UI Thread).
}
}
.....
?>
Thanks!
Michael Brown
360 Replays Ltd.
I've been searching for a solution on google for a problem related to
creating events from a worker thread, with no luck..
Basically, the problem is when my events are caught by a UI using my
class, they get the usual "Control 'blah' accessed from a thread other
than the thread it was created on.". I understand that of course, but
my class is to be distributed to people who don't want to have to worry
about invoking delegates in the event handler, I want to keep it all
neat and tidy inside the class and they can do whatever they want in
the events I throw. Is there a way to launch my event on the thread the
class was created on, instead of my worker thread? I've tried using a
delegate thinking that would work, but it doesn't. I've also tried
inheriting from Control and using Invoke, which doesn't seem to work as
well.
Is there something I'm missing to easily accomplish this within my
class?
<?
.....
public myclass()
{
readThread = new Thread(new ThreadStart(ThreadLoop));
}
public void ThreadLoop()
{
while(some waithandle)
{
if(something)
if(myevent!=null) myevent(this, new args(1,2,3,4));
// instead of calling the above event here, I need to trigger
something
// in the thread the class was created on (UI Thread).
}
}
.....
?>
Thanks!
Michael Brown
360 Replays Ltd.