windows 服务器无法在 .net Framework 4.5.1 上运行
windows server is not working on .net framework 4.5.1
我试图在 windows 服务器 2012 上安装 windows 服务,但这个错误总是 return 我
Error 1053: The service did not respond to the start or control
request in a timely fashion
这是我启动 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 Framework 4.5.2 上工作
就我而言,我在 Entity framework
中遇到了问题
所以我检查了服务器上安装的最新 entity framework 和 Entity framework 4.5.2
没有安装在 windows 服务器 2012 上,所以我从 Microsoft 网站安装了它 https://www.microsoft.com/en-us/download/details.aspx?id=42637 然后我重新启动了我的服务器,它现在工作正常
我试图在 windows 服务器 2012 上安装 windows 服务,但这个错误总是 return 我
Error 1053: The service did not respond to the start or control request in a timely fashion
这是我启动 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 Framework 4.5.2 上工作
就我而言,我在 Entity framework
所以我检查了服务器上安装的最新 entity framework 和 Entity framework 4.5.2
没有安装在 windows 服务器 2012 上,所以我从 Microsoft 网站安装了它 https://www.microsoft.com/en-us/download/details.aspx?id=42637 然后我重新启动了我的服务器,它现在工作正常