Click here to Skip to main content
Rate this: bad
good
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 20:34pm
Edited 8-Oct-12 20:50pm
v2

1 solution

Rate this: bad
good
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.
  Permalink  
v2
Comments
Oshtri Deka at 9-Oct-12 3:48am
   
5
Zoltán Zörgő at 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
0 OriginalGriff 259
1 Sergey Alexandrovich Kryukov 182
2 Hard_Rockz 153
3 Richard MacCutchan 125
4 Maciej Los 104
0 OriginalGriff 5,374
1 Sergey Alexandrovich Kryukov 4,713
2 Peter Leow 2,944
3 DamithSL 2,465
4 Maciej Los 2,270


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