?
Solved

C# Windows Service

Posted on 2013-06-21
5
Medium Priority
?
351 Views
Last Modified: 2013-06-21
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
0
Comment
Question by:jeffreyjseaman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 39266869
What I would normally do is keep the service running.

Based on the frequency of the messages, adn the responsiveness you need, put the thread ot sleep before looping.

Essentially:

while (1)
{
  ProcessQueue();
  Thread.CurrentThread.Sleep(x);  //Seconds, minutes hours?
}
0
 

Author Comment

by:jeffreyjseaman
ID: 39267202
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
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39267215
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
0
 

Author Comment

by:jeffreyjseaman
ID: 39267261
Thank You. I will try this out. Appreciate your help.
0
 

Author Closing Comment

by:jeffreyjseaman
ID: 39267262
What I wanted.. Thank You...
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question