我看过其他一些关于此的文章,但是他们提出的解决方案没有用。我尝试安装发布模式exe,并尝试添加:
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
至app.config。据说它应该等待30秒才能超时并失败,但是它几乎在启动服务后立即发生。
我的main()
如下:
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new ReportGeneratorService()
};
ServiceBase.Run(ServicesToRun);
}
我的服务类别如下:
public partial class ReportGeneratorService : ServiceBase
{
private Timer workTimer;
private JobQueue jq = new JobQueue();
public ReportGeneratorService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
base.OnStart(args);
workTimer = new Timer(new TimerCallback(LoadAndExecuteJobs), null, 0, 60*1000);
}
protected override void OnStop()
{
workTimer.Dispose();
base.OnStop();
}
private void LoadAndExecuteJobs(object state)
{
if (jq.JobStatusID != 2)
{
jq.LoadJob();
jq.ExecuteJob(ConfigurationManager.AppSettings.Get("TempReportFolder"));
}
}
}