Click here to Skip to main content
12,821,494 members (29,298 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET
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 8-Oct-12 21:34pm
Updated 8-Oct-12 21:50pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Oshtri Deka 9-Oct-12 3:48am
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100