Click here to Skip to main content
15,892,746 members
Home / Discussions / C#
   

C#

 
AnswerRe: Regarding Modbus Pin
Pete O'Hanlon23-Aug-12 4:30
mvePete O'Hanlon23-Aug-12 4:30 
Questionpassing enum value to other method in different namespace Pin
Blubbo23-Aug-12 1:59
Blubbo23-Aug-12 1:59 
AnswerRe: passing enum value to other method in different namespace Pin
Pete O'Hanlon23-Aug-12 2:03
mvePete O'Hanlon23-Aug-12 2:03 
GeneralRe: passing enum value to other method in different namespace Pin
Blubbo23-Aug-12 2:15
Blubbo23-Aug-12 2:15 
AnswerRe: passing enum value to other method in different namespace Pin
DaveyM6923-Aug-12 2:04
professionalDaveyM6923-Aug-12 2:04 
AnswerRe: passing enum value to other method in different namespace Pin
pramod.hegde23-Aug-12 20:21
professionalpramod.hegde23-Aug-12 20:21 
GeneralRe: passing enum value to other method in different namespace Pin
Blubbo27-Aug-12 2:04
Blubbo27-Aug-12 2:04 
QuestionLet Windows service OnStop() wait longer Pin
Mc_Topaz23-Aug-12 1:32
Mc_Topaz23-Aug-12 1:32 
I have a Windows service which I sometimes cannot properly stop. Sometimes I get "Error 1053". Error 1053 is an error when a time-out has elapsed for starting and stopping services. Simple terms: It takes to long to start or stop a service.

By trial and error I have found out, on my computer, that it takes about 2 minutes and 10 seconds for the error to occur. 2 min and 5 sec is fine.

When I'm trying to stop the service the service might be in a process to read and export data. This process maybe takes some seconds or maybe a minutes to complete. I can never tell how long time the procedure takes.

I would like to finish the process and then stop the service. But since it can take up to minutes to finish the process I'm sure I'll spend to much time in the OnStop() method.

I have tried the Service.RequestAdditionalTime() method to give the service more time to wait so my process can finish. But "Error 1053" still occur for me.
I have tried with 10 ms and 1000ms. No success!

My code is basically this, very simplified:

C#
using System;
using System.ServiceProcess;
using System.Threading;

public class Application
{
    // These should be private fields, but I don't care about that now...
    public bool running = true;
    public bool terminated = false;

    public void MainLoop()
    {
        while(running)
        {
            ReadData();   // This method may take several minutes to complete
            ExportData();
        }

        terminated = true;
    }

    private void ReadData()
    {
        // Do some work which may take time, several minutes

        // Let say this method takes 3 minutes to complete
    }
    
    private void ExportData()
    {
        // Export data
    }
}

public partial class Service: ServiceBase
{
    Application application;

    public Service()
    {
        InitializeComponent();
    }

    public OnStart()
    {
        this.application = new Application();

        Thread mainLoopThread = new Thread(application.MainLoop);
        mainLoopThread.Start();
    }

    public OnStop()
    {
        applicaiton.running = false;

        while(application.terminated == false)
        {
            this.RequestAdditionalTime(1000);
        }
    }
}



Let's assume the Application.ReadData() method takes 3 minutes to complete. Much longer than the OnStop() method is allowed to run.

How can make OnStop() method accept longer time to wait?
AnswerRe: Let Windows service OnStop() wait longer Pin
Eddy Vluggen23-Aug-12 1:45
professionalEddy Vluggen23-Aug-12 1:45 
GeneralRe: Let Windows service OnStop() wait longer Pin
Mc_Topaz23-Aug-12 3:01
Mc_Topaz23-Aug-12 3:01 
GeneralRe: Let Windows service OnStop() wait longer Pin
Eddy Vluggen23-Aug-12 3:06
professionalEddy Vluggen23-Aug-12 3:06 
AnswerRe: Let Windows service OnStop() wait longer Pin
BobJanova23-Aug-12 2:37
BobJanova23-Aug-12 2:37 
GeneralRe: Let Windows service OnStop() wait longer Pin
Mc_Topaz23-Aug-12 3:03
Mc_Topaz23-Aug-12 3:03 
GeneralRe: Let Windows service OnStop() wait longer Pin
PIEBALDconsult23-Aug-12 3:06
mvePIEBALDconsult23-Aug-12 3:06 
GeneralRe: Let Windows service OnStop() wait longer Pin
Mc_Topaz23-Aug-12 3:39
Mc_Topaz23-Aug-12 3:39 
GeneralRe: Let Windows service OnStop() wait longer Pin
BobJanova23-Aug-12 3:37
BobJanova23-Aug-12 3:37 
AnswerRe: Let Windows service OnStop() wait longer Pin
jschell23-Aug-12 8:47
jschell23-Aug-12 8:47 
AnswerRe: Let Windows service OnStop() wait longer Pin
Vijay Selvaraj26-Aug-12 22:00
Vijay Selvaraj26-Aug-12 22:00 
QuestionSystem.Drawing.Pen-type property does not expand in property grid Pin
TetheredSun22-Aug-12 22:51
TetheredSun22-Aug-12 22:51 
AnswerRe: System.Drawing.Pen-type property does not expand in property grid Pin
Eddy Vluggen23-Aug-12 1:12
professionalEddy Vluggen23-Aug-12 1:12 
GeneralRe: System.Drawing.Pen-type property does not expand in property grid Pin
TetheredSun23-Aug-12 1:34
TetheredSun23-Aug-12 1:34 
GeneralRe: System.Drawing.Pen-type property does not expand in property grid Pin
Eddy Vluggen23-Aug-12 1:43
professionalEddy Vluggen23-Aug-12 1:43 
GeneralRe: System.Drawing.Pen-type property does not expand in property grid Pin
TetheredSun23-Aug-12 1:46
TetheredSun23-Aug-12 1:46 
GeneralRe: System.Drawing.Pen-type property does not expand in property grid Pin
Eddy Vluggen23-Aug-12 2:04
professionalEddy Vluggen23-Aug-12 2:04 
QuestionSerialPort open, but receive no response Pin
LionAM22-Aug-12 21:11
LionAM22-Aug-12 21:11 

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.