Solved

C# Windows Service

Posted on 2013-06-21
5
349 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
write html in textarea and record it into a database table 3 40
aspx ascx, c# 7 41
Difference between Leaflet and MapBox? 5 45
What is needed to become a DBA? 7 51
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

737 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