【发布时间】:2011-08-18 18:14:01
【问题描述】:
我正在尝试创建我的第一个 Windows 服务,但很伤心......在我从 services.msc 手动启动服务后,消息“本地计算机上的服务启动然后停止。一些服务会自动停止,因为它们没有工作要做'
我确定我的代码中一定有错误...
namespace ConvertService
{
public partial class Service1 : ServiceBase
{
public Service1()
{
this.ServiceName = "ConvertService";
this.EventLog.Log = "Application";
}
static void main()
{
ServiceBase.Run(new Service1());
}
protected override void OnStart(string[] args)
{
Process pMP3 = new Process();
pMP3.StartInfo.UseShellExecute = false;
pMP3.StartInfo.RedirectStandardOutput = true;
pMP3.StartInfo.FileName = @"d:\...path...\converter.exe";
pMP3.StartInfo.Arguments = @"d:\...path...\tempamr.amr " + @"d:\...path...\tempmp3.mp3 " + @"-cmp3";
pMP3.Start();
pMP3.WaitForExit();
Process pWAV = new Process();
pWAV.StartInfo.UseShellExecute = false;
pWAV.StartInfo.RedirectStandardOutput = true;
pWAV.StartInfo.FileName = @"d:\...path...\converter.exe";
pWAV.StartInfo.Arguments = @"d:\...path...\tempmp3.mp3 " + @"d:\...path...\tempwav.wav " + @"-cwav";
pWAV.Start();
pWAV.WaitForExit();
}
protected override void OnStop()
{
}
}
}
如果我犯了愚蠢的错误,请原谅我。这是我的第一个 Windows 服务。
PS。我已经勾选了“允许服务与桌面交互”
【问题讨论】:
-
查看 Windows 事件日志。它可能与您的代码轰炸未处理的异常有关。
标签: c# process windows-services