Click here to Skip to main content
15,905,419 members
Home / Discussions / C#
   

C#

 
GeneralRe: displaying progress bar in background worker thread C# Pin
evrajo1-Jun-10 0:05
evrajo1-Jun-10 0:05 
GeneralRe: displaying progress bar in background worker thread C# Pin
Pete O'Hanlon1-Jun-10 0:08
mvePete O'Hanlon1-Jun-10 0:08 
GeneralRe: displaying progress bar in background worker thread C# Pin
Pete O'Hanlon1-Jun-10 0:06
mvePete O'Hanlon1-Jun-10 0:06 
AnswerRe: displaying progress bar in background worker thread C# Pin
DaveyM691-Jun-10 0:31
professionalDaveyM691-Jun-10 0:31 
AnswerRe: displaying progress bar in background worker thread C# Pin
PIEBALDconsult1-Jun-10 4:38
mvePIEBALDconsult1-Jun-10 4:38 
QuestionExcel Workbook Save copy error in Windows 2003 server Pin
kumuda.t31-May-10 23:27
kumuda.t31-May-10 23:27 
AnswerRe: Excel Workbook Save copy error in Windows 2003 server Pin
Henry Minute1-Jun-10 0:54
Henry Minute1-Jun-10 0:54 
Questionrecord voice and phone number of central phone device Pin
mr.mohsen31-May-10 21:53
mr.mohsen31-May-10 21:53 
QuestionHelp required in Threading.. Pin
NetMan201231-May-10 21:36
NetMan201231-May-10 21:36 
AnswerRe: Help required in Threading.. Pin
Stanciu Vlad31-May-10 21:46
Stanciu Vlad31-May-10 21:46 
AnswerRe: Help required in Threading.. Pin
mr.mohsen31-May-10 21:56
mr.mohsen31-May-10 21:56 
GeneralRe: Help required in Threading.. Pin
NetMan20121-Jun-10 1:14
NetMan20121-Jun-10 1:14 
GeneralRe: Help required in Threading.. Pin
#realJSOP1-Jun-10 1:41
professional#realJSOP1-Jun-10 1:41 
AnswerRe: Help required in Threading.. Pin
Mycroft Holmes31-May-10 21:57
professionalMycroft Holmes31-May-10 21:57 
AnswerRe: Help required in Threading.. Pin
Henry Minute1-Jun-10 0:57
Henry Minute1-Jun-10 0:57 
GeneralRe: Help required in Threading.. Pin
Luc Pattyn1-Jun-10 2:51
sitebuilderLuc Pattyn1-Jun-10 2:51 
GeneralRe: Help required in Threading.. Pin
Henry Minute1-Jun-10 3:09
Henry Minute1-Jun-10 3:09 
GeneralRe: Help required in Threading.. Pin
harold aptroot1-Jun-10 3:24
harold aptroot1-Jun-10 3:24 
GeneralRe: Help required in Threading.. Pin
Luc Pattyn1-Jun-10 3:51
sitebuilderLuc Pattyn1-Jun-10 3:51 
Questionremote debugging? Pin
swjam31-May-10 20:01
swjam31-May-10 20:01 
AnswerRe: remote debugging? Pin
Abhinav S31-May-10 20:49
Abhinav S31-May-10 20:49 
QuestionC# 2.0 Windows Service - Memory Leak? [modified] Pin
SarahMcM31-May-10 18:08
SarahMcM31-May-10 18:08 
I have a windows service in C# .net 2.0. At the moment all it is doing is being instantiated, setting up a timer and then every interval (eg 1 minute) writing to a log file. The memory usage on TaskManager goes up and up ...

I can't see any objects that I've left lying around - I've taken out pretty much everything it is meant to do ... perhaps I'm being paranoid and the garbage collector will come and clean up when it is ready? How long should I leave it? It's been a while since the last Windows Service I wrote ... any ideas?

Thanks in advance Smile | :)

Here are some excerpts from the code...

The LogFile is a static class with a single static method "Write"

public static class LogFile
{

    public static void Write(string message)
    {
        string logFileName = (String)(new AppSettingsReader()).GetValue("log-file-path", typeof(String)) + "FileLoaderServiceLog.txt";

        File.AppendAllText(logFileName, DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + " FileLoaderService:" + "    " + message + Environment.NewLine);
    }


The Service class itself
public partial class FileLoaderService : ServiceBase
{

    private Timer serviceTimer;

    public FileLoaderService()
    {
        InitializeComponent();

        serviceTimer = new Timer();
        double intervalInMinutes = (double)(new AppSettingsReader()).GetValue("timer-interval-in-minutes", typeof(double));
        serviceTimer.Interval = intervalInMinutes * 60 * 1000; //intervalInMinutes * 60 seconds * 1000ms
        serviceTimer.Elapsed += new ElapsedEventHandler(serviceTimer_Elapsed);
    }

    protected override void OnStart(string[] args)
    {
        LogFile.Write("Service Started - starting timer");
        serviceTimer.Start();
    }

    protected void serviceTimer_Elapsed(object sender, ElapsedEventArgs e)
    {
        //stop timer whilst we process
        serviceTimer.Stop();

        //do processing
        //have removed this to try to find the "leak"
        LogFile.Write("Checking Queue...");

        //processing done - start it up again
        serviceTimer.Start();
    }

    protected override void OnStop()
    {
        serviceTimer.Stop();
        serviceTimer = null;
        LogFile.Write("Service Stopped");
    }
}


And Program Main ...

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()
    {
        ServiceBase[] ServicesToRun;

        //// More than one user Service may run within the same process. To add
        //// another service to this process, change the following line to
        //// create a second service object. For example,
        ////
        ////   ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
        ////

        ServicesToRun = new ServiceBase[] { new FileLoaderService() };

        ServiceBase.Run(ServicesToRun);

    }
}


modified on Tuesday, June 1, 2010 6:24 PM

AnswerRe: C# 2.0 Windows Service - Memory Leak? Pin
Pete O'Hanlon31-May-10 21:42
mvePete O'Hanlon31-May-10 21:42 
GeneralRe: C# 2.0 Windows Service - Memory Leak? Pin
SarahMcM1-Jun-10 12:22
SarahMcM1-Jun-10 12:22 
AnswerRe: C# 2.0 Windows Service - Memory Leak? Pin
#realJSOP1-Jun-10 0:06
professional#realJSOP1-Jun-10 0:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.