Windows服务器无法在.net框架4.5.1上运行

问题描述 投票:0回答:1

我试图在Windows Server 2012上安装Windows服务但这个错误总是返回给我

错误1053:服务未及时响应启动或控制请求

这是我如何开始我的Windows服务:

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)
        {

        }

    }

我认为它导致我的Windows服务在.net框架4.5.2上工作

c# windows-services
1个回答
0
投票

在我的情况下,我在Entity framework有问题

所以我检查了服务器上安装的最新实体框架和Entity framework 4.5.2

没有安装在Windows Server 2012上所以我从微软网站https://www.microsoft.com/en-us/download/details.aspx?id=42637安装它然后我重新启动我的服务器,它的工作正常

© www.soinside.com 2019 - 2024. All rights reserved.