设计了一个windows service来自动scan目录,如果有文件先做一些检查工作,然后upload到ftp上
code如下,DoWork 会做具体工作,现在的问题是这个windows service会自动stop,为什么? protected override void OnStart(string[] args)
{
File.Delete(@"C:\OrderGen\Scripts\FTPSenderLog.txt");
_thread = new Thread(WorkerThreadFunc);
_thread.Name = "PNI FtpSend Thread";
_thread.IsBackground = true;
_thread.Start(); } protected void WorkerThreadFunc()
{
while (!_shutdownEvent.WaitOne(0))
{
DoWork();
}
} protected override void OnStop()
{
_shutdownEvent.Set();
if (!_thread.Join(3000))
{
// give the thread 3 seconds to stop
_thread.Abort();
}
}
code如下,DoWork 会做具体工作,现在的问题是这个windows service会自动stop,为什么? protected override void OnStart(string[] args)
{
File.Delete(@"C:\OrderGen\Scripts\FTPSenderLog.txt");
_thread = new Thread(WorkerThreadFunc);
_thread.Name = "PNI FtpSend Thread";
_thread.IsBackground = true;
_thread.Start(); } protected void WorkerThreadFunc()
{
while (!_shutdownEvent.WaitOne(0))
{
DoWork();
}
} protected override void OnStop()
{
_shutdownEvent.Set();
if (!_thread.Join(3000))
{
// give the thread 3 seconds to stop
_thread.Abort();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货