DoEvents in Windows Service

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
E

Elmo Watson

I have a windows service that, technically works most of the time, but I
think I'm running into a situation that is caused due to actions being
started before the last action is completed.

In a Windows Forms application, I'd do this to overcome this:
System.Windows.Forms.Application.DoEvents

However, in my designer for the Windows Service (using the FileWatcher),
this is not available

So, how can I accomplish 'DoEvents' in a Windows Service?
 
I have a windows service that, technically works most of the time, but I
think I'm running into a situation that is caused due to actions being
started before the last action is completed.

In a Windows Forms application, I'd do this to overcome this:
System.Windows.Forms.Application.DoEvents

However, in my designer for the Windows Service (using the FileWatcher),
this is not available

So, how can I accomplish 'DoEvents' in a Windows Service?

Are you using multiple threads ? If yes, then synchronize them, to
avoid these kind of situations.
 
Elmo Watson said:
I'm running into a situation that is caused due to actions being
started before the last action is completed.
The service needs to have some sort of synchronization code to ensure the
events run in order. If action B depends on A having finished, then B needs
to check that A is done before running. The details will be specific to your
app.
In a Windows Forms application, I'd do this to overcome this:
System.Windows.Forms.Application.DoEvents
This is almost always a bad idea. DoEvents starts a second message pump and
can cause reentrancy problems such as what you describe. It should only be
used very deliberately and not as a generic "fix me" API.
So, how can I accomplish 'DoEvents' in a Windows Service?
DoEvents runs the message pump. Since services do not generally have
windows, they don't generally pump messages.

--Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top