【问题标题】:windows server is not working on .net framework 4.5.1Windows 服务器无法在 .net 框架 4.5.1 上运行
【发布时间】:2026-02-24 15:30:01
【问题描述】:

我试图在 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 上工作

【问题讨论】:

  • 请发GeneralMethods.createLogFile的代码
  • @CamiloTerevinto 功能已添加...

标签: c# windows-services


【解决方案1】:

就我而言,Entity framework 有问题

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

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

【讨论】:

    最近更新 更多