I have created multithreading inside windows service. I have a timer inside the windows service so that every 5 minutes it will run the service. Inside the service, I have created 10 threads to do parallel task.
The Problems I am facing:
1. Sometimes the windows services become stop. I have to manually start it again. Why it happen and how to resolve it?
2. Instead of thread, if I create 10 windows service, then it is faster than 10 threads. So how can I do it with multi-threading?
I give you the exact scenario that I want to do So that it will be easy to get the real picture:
I have created an application to send message. I am receiving more message in every minute. I have to broadcast them as fast as possible.
Now currently I have created 30 windows services and each windows service broadcast the message. If do some changes, then I have to do in 30 windows services. So, I have created one windows service which will create 30 threads and start broadcasting the message. But I see it's sending speed slower than my previous 30 windows service do.
So how can I resolve this problem?
Please help and advice.
Thanks in advance.
Akkiraju IvaturiPosted Jan 17, 2013, 9:12 AM
Your approach creating threads in one service is perfect and that is the way you need to design the service. Regarding why the service is stopped, you might have to look into the following aspects:
1. Decorate your methods OnStart() and Main() with proper try catch.
2. Log when the service is started ands stopped in the OnStart() and OnStop() methods.
3. If you want to see why the service is stopped go to Event Viewer and check. You should be having appropriate error messages logged that may be useful.
4. Also set your service to run as automatic. Because sometimes when any upgrades to the servers restarts the system and if your service is running as manual, it will be stopped.
It is not a standard practice to create multiple window services for one task. If you have any questions, feel free to ask.