C#Windows服务未执行某些代码
我已经实现了一个运行良好的windows窗体应用程序,之后我决定将该windows窗体应用程序转换为windows服务C#Windows服务未执行某些代码,c#,debugging,windows-services,event-log,C#,Debugging,Windows Services,Event Log,我已经实现了一个运行良好的windows窗体应用程序,之后我决定将该windows窗体应用程序转换为windows服务 EventLog.WriteEntry("Before Calling Invoices1"); 这一行是服务的第一行,工作正常,我可以在事件查看器中看到日志, 下一行是函数调用 bool ff = LoginLogoutAction(true); 这个函数的第一行是 EventLog.WriteEntry("inside LoginLogoutAction"); 这一行
EventLog.WriteEntry("Before Calling Invoices1");
这一行是服务的第一行,工作正常,我可以在事件查看器中看到日志,
下一行是函数调用
bool ff = LoginLogoutAction(true);
这个函数的第一行是
EventLog.WriteEntry("inside LoginLogoutAction");
这一行永远不会执行,调用函数后的这一行也永远不会执行我到处都有try catch,但代码永远不会到达catch,它只是停止,服务仍在运行,下次服务执行时也会发生同样的事情(服务每分钟执行一次)
我已编辑该服务以作为管理员登录,但未解决此问题
登录功能是:
private bool LoginLogoutAction(bool bLogin)
{
EventLog.WriteEntry("inside LoginLogoutAction");
try
{
strCurrentServiceURL = "https://10.0.0.10:50000/b1s/v1/";
currentConnectionInfo.CompanyDB = "ALLAYAN";
currentConnectionInfo.UserName = "manager";
currentConnectionInfo.Password = "1234";
if (bLogin)
{
EventLog.WriteEntry("Inside if statement");
//System.Windows.Forms.MessageBox.Show("Please wait while login...");
currentOdataService.InitServiceContainer(strCurrentServiceURL);
if (!currentConnectionInfo.IsValid())
{
EventLog.WriteEntry("Inside if not valid will get out login failed");
//System.Windows.Forms.MessageBox.Show("Make sure correct user name, password and company database provided");
return false;
}
EventLog.WriteEntry("before logging in");
B1Session session = currentOdataService.LoginServer(currentConnectionInfo);
EventLog.WriteEntry("after logging in");
if (null != session)
{
//bConnected = true;
string strDisplay = currentOdataService.GetRequestHeaders() + currentOdataService.GetResponsetHeaders() + Newtonsoft.Json.JsonConvert.SerializeObject(session, Newtonsoft.Json.Formatting.Indented);
return true;
}
else
{
EventLog.WriteEntry("Session is null");
return false;
//button9.BackColor = Color.Red;
//bConnected = false;
//button9.Text = "Login";
//System.Windows.Forms.MessageBox.Show("Failed to login, please make sure server is running and the credentials are correct.");
}
}
else
{
//bConnected = false;
currentOdataService.LogoutServer();
return true;
//button9.Text = "Login";
//button9.BackColor = Color.Empty;
//System.Windows.Forms.MessageBox.Show("Logout from service successfully");
}
return true;
}
catch (Exception ex)
{
EventLog.WriteEntry("Error while logging in " + ex.Message + ex.InnerException.Message);
return false;
}
}
你能发布函数的主体吗?可能是访问权限问题?您是否尝试过以运行windows窗体应用程序的同一用户的身份运行windows服务?这在很大程度上取决于登录的内容does@johnyTee我已经更新了问题并发布了问题的正文function@schlonzo是的,我试过了