【发布时间】:2012-11-21 15:16:20
【问题描述】:
我编写了一个 Windows 服务,它又调用了一个 Web 服务。 当我从测试应用程序运行 Windows 服务时,它运行良好。但是,当我安装该服务然后启动它时,它几乎立即停止。我在日志中看到的仅有的两个条目是 Constructor 和 Thread Started。不知道出了什么问题。
public partial class WindowsService : ServiceBase
{
public LogManager.LogFile _log;
public Thread m_thread;
protected TimeSpan m_delay;
CommonFunctions _cf = new CommonFunctions();
DBFunctions _db = new DBFunctions();
public WindowsService()
{
InitializeComponent();
_log = new LogManager.LogFile(@"c:\test\servicelog.txt", true, true);
_log.WriteToLog("Constructor", LogLevel.Level0);
}
protected override void OnStart(string[] args)
{
m_delay = new TimeSpan(0,0,300);
base.OnStart(args);
try
{
m_thread = new System.Threading.Thread(Execute);
m_thread.Start();
_log.WriteToLog("Thread Started", LogLevel.Level0);
}
catch (Exception ex)
{ _log.WriteToLog(ex.Message, LogLevel.Level0); }
}
public void Execute()
{
_log.WriteToLog("Begin Execute...", LogLevel.Level0);
try
{
ProcessNewLMSUsers();
}
catch (Exception ex)
{
_log.WriteToLog(ex.Message.ToString());
}
}
private void ProcessNewLMSUsers()
{
try
{
_log.WriteToLog("Begin: Processing new LMS Users", LogLevel.Level1);
// Check for new users in the LMS.
string callErrorText = "";
bool userAdded = false;
LMSWS.SSO lms = _cf.GetLMSSSOWS(); **// this is a web service**
lms.Timeout = 99999;
}
REST OF THE CODE.................
}
【问题讨论】:
-
你检查过系统日志吗?看看这个问题的公认答案以获得概述。 stackoverflow.com/questions/1067531/…