0
votes

I trying to install windows service on windows server 2012 but this error always return to me

Error 1053: The service did not respond to the start or control request in a timely fashion

this how I start my windows service:

protected override void OnStart(string[] args)
{

    try
    {

        int serviceWorkingDurationSecond = int.Parse(ConfigurationManager.AppSettings["serviceWorkingDurationSeconds"].ToString());

        // For first time, set amount of seconds between current time and schedule time
        _timer = new System.Timers.Timer();

        _scheduleTime = DateTime.Today.AddMinutes(serviceWorkingDurationSecond); // Schedule to run once a day at 9:00 p.m.
        if (_scheduleTime.Subtract(DateTime.Now).TotalSeconds * 1000 <= 0)
            _scheduleTime = DateTime.Today.AddDays(1).AddMinutes(serviceWorkingDurationSecond); // Schedule to run once a day at 9:00 p.m.
        _timer.Enabled = true;
        _timer.Interval = _scheduleTime.Subtract(DateTime.Now).TotalSeconds * 1000;
        _timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed);
    }
    catch (Exception ex)
    {
        GeneralMethods.createLogFile("OnStart() Function error*** " + ex.ToString());
    }
}

private static object _lock = new object();
    public static void createLogFile(string errorMsg)
    {
        try
        {
            lock (_lock)
            {
                string appDirectory = Path.GetDirectoryName(Application.ExecutablePath);
                if (!Directory.Exists(appDirectory + "\\Log"))
                {
                    DirectoryInfo di = Directory.CreateDirectory(appDirectory + "\\Log");//create folder in direction if not exists
                }
                File.AppendAllText(appDirectory + "\\Log\\Log.txt", errorMsg + Environment.NewLine);
            }
        }
        catch (Exception ex)
        {

        }

    }

I think its cause my windows service work on .net framework 4.5.2

1
Please post the code for GeneralMethods.createLogFile - Camilo Terevinto
@CamiloTerevinto function added... - Mohammed Alasa'ad

1 Answers

0
votes

In my case I had problem in Entity framework

So I checked the latest entity framework installed on the server and the Entity framework 4.5.2

does not installed on windows server 2012 so I installed it from Microsoft website https://www.microsoft.com/en-us/download/details.aspx?id=42637 then I restart my server and its working fine now