event handling

  • Thread starter Thread starter Srini
  • Start date Start date
S

Srini

My application has a proprietry activex plugin that
raises events. When an event is fired, my app needs to
some processing(1 to 2 secs). Events can fire in quick
succession... somethings even before a prior event has
been processed. This is messing up my logic as the
application is highly state based.

What's the best practice to handle this kind of scenario?
Is there a way to queue up the events or block (but not
cancel) the events till the one being processed is
completed? Any suggestions are sincerely welcome.

Thanks
 
Hi Srini,

It sounds like a job for a thread. The event handler would place a 'job' on a queue
which the thread would work off.

The worker thread and queue could be in the same class. When the first job is placed
on the queue, the worker class starts up the thread and off it goes. When the queue is
empty, the thread goes to sleep.

If these events are occuring throughout the lifetime of the app, keep the same thread
rather than killing it and creating a new one. If there are large periods of inactivity,
you may want to kill the thread after sleeping for a certain time.

You'd have to have locking on the queue so that the event handler and thread don't
clash when accessing it.

Regards,
Fergus

[ I'm very rarely in this group - just popping in for a peep. ]
 
Hi Fergus,

Thanks for your suggestion. I was looking for any inbuilt
support in the .Net framework to accomplish this.

Thanks,
Srini
-----Original Message-----
Hi Srini,

It sounds like a job for a thread. The event handler would place a 'job' on a queue
which the thread would work off.

The worker thread and queue could be in the same
class. When the first job is placed
on the queue, the worker class starts up the thread and off it goes. When the queue is
empty, the thread goes to sleep.

If these events are occuring throughout the lifetime
of the app, keep the same thread
rather than killing it and creating a new one. If there
are large periods of inactivity,
you may want to kill the thread after sleeping for a certain time.

You'd have to have locking on the queue so that the event handler and thread don't
clash when accessing it.

Regards,
Fergus

[ I'm very rarely in this group - just popping in for a peep. ]


.
 
Back
Top