我想创建我的第一个Windows服务,但很伤心......在我从services.msc手动启动服务之后,消息'本地计算机上的服务启动并停止。一些服务自动停止,是他们没有工作要做”C#Windows服务 - 本地计算机上的服务已启动,然后停止?
我相信一定有我的代码中的一些错误...
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事件日志。它可能有一些关于你的代码轰炸未处理的异常。 –