Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed an C# windows form application and it seems to consume more memory. I tried making it more efficient and I got an idea if it is a better idea to implement the functionality in a windows service application rather, so that I can make the application to pause and resume automatically so that I can save some processessing memory. Will windows Service be an efficient approach to this solution?

Another question:
Is it possible to create a thread inside the service which will be active even if the service is paused or stopped? My requirement is that I wanted the thread to check for the internet connectivity at all times when the computer is ON and if the connection is established the service must be started or continued, and at other
conditions the service should be paused or stopped.

Is it possible to just have a simple thread running in the backgroud which will check for internet connectivity and if the connection is established I want the service to be started. How to create a thread process in visual studio?

Pls help me out guys. Thanks in advance.
Posted
Updated 8-Oct-12 20:50pm
v2

1 solution

First question: There will be no actual difference in performance. The business logic will be the same. You will be noticing considerable difference only if the GUI is consuming your resources, but than you have an other kind of problem, and I can not imagine a gui intensive application running as service.

Second question: pausing a service does nothing by itself. You are responsible of your threads in the service. You have to pause or stop your threads. Buy you don't have to run your thread all the time, you can use Thread.Sleep[^], to make your thread sleep a while. So pausing/stoping and restarting a service is not a good idea, it is a waste of resources. You can even use IPC methods or thread synchronization methods to have separate parts of your solution work together as needed.

Third question: You can not have a limbo thread somewhere. A thread belongs to a process. Think of your service not as a single threaded application. You can have many threads in a service: like a connection watcher and working thread. You can use thread control and synchronization methods from the watcher thread to pause/resume or restart you worker thread(s) rather than your whole service.
 
Share this answer
 
v2
Comments
Oshtri Deka 9-Oct-12 3:48am    
5
Zoltán Zörgő 9-Oct-12 3:49am    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900