Link to home
Start Free TrialLog in
Avatar of jeffreyjseaman
jeffreyjseaman

asked on

C# Windows Service

I have C# Windows Service written and it works fine. When I start the services it executes the commands and does what it needs to do and then stop.

What I need it to do is the following;

1. Listen to when a new message is available via IBM MQ and then start the services automatically.

How can I accomplish this? Should my service not stop and run constantly v/s stopping and then starting back up. Any suggestions, code examples etc; would be greatly appreciated.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jeffreyjseaman
jeffreyjseaman

ASKER

Hi Thanks,

So if I do the Thread.CurrentThread.Sleep(x); // whatever amount of seconds 500 seconds..
Will the Service automatically start back up after the 500 seconds or whatever the set time was?

Thanks
Jeff
If it's in a loop yes.

essentially you keep in "running" the entire time.  After the 500 seconds (note sleep is in MS, so it would be 500,000 you would pass in the value for 500 seconds), it would wake itself up and continue to run.  You hold onto any memory you used, but no CPU cycles are wasted during the  sleep time.

Note you should also handle the stop event.

http://code.msdn.microsoft.com/windowsdesktop/CSWindowsService-9f2f568e
Thank You. I will try this out. Appreciate your help.
What I wanted.. Thank You...