Solved

C# Windows Service

Posted on 2013-06-21
5
345 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
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

803 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