问题描述
我正在使用Quartz运行一些计划的作业。作业运行时,它将调用命令行程序执行某项操作。代码如下:
public async System.Threading.Tasks.Task Execute(IJobExecutionContext context)
{
// ...... get some parameters
// ...
try
{
// skip some details...
// Now we decided to run
if (!isstop)
{
if (tc.IsActive)
{
// check whether in the start time and end time
// if null,skip these
var dtNow = DateTime.Now;
if (tc.StartDate.Year > 2000 && tc.StartDate > dtNow)
{
isstop = true;
}
if (tc.EndDate.Year > 2000 && tc.EndDate < dtNow)
{
isstop = true;
}
if (!isstop)
{
// Now,start exe
LaunchCommandLineApp(timeout,dll_fullname,dll_para_json,guid);
}
else
{
_log4net.Info($"TaskConfigId: {taskConfigId}: Quartz Execute: {dll_fullname}: Skip.");
}
}
else
{
_log4net.Info($"TaskConfigId: {taskConfigId}: Quartz Execute: {dll_fullname}: InActive.");
}
}
}
catch (Exception ex)
{
_log4net.Error($"TaskConfigId: {taskConfigId}: Quartz Execute Exception: {ex}",ex);
}
finally
{
// ...
_log4net.Info($"TaskConfigId: {taskConfigId}: Quartz Execute: {dll_fullname}: Done.");
}
}
private void LaunchCommandLineApp(int timeout,string fullname,string paraJson,Guid guid)
{
// Use processstartinfo class
processstartinfo startInfo = new processstartinfo();
startInfo.CreateNowindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "MyConsole.exe";
// ....
try
{
// Start the process with the info we specified.
using (Process p = Process.Start(startInfo))
{
// ****
var isTimeOut = p.WaitForExit(timeout * 1000);
_log4net.Info($"{fullname}: Done. isTimeOut: {isTimeOut}."); // line A
}
}
catch (Exception ex)
{
_log4net.Error(string.Format("Error in running process: {0}: {1}",fullname,ex.ToString()),ex); // Line B
throw ex;
}
}
启动MyConsole.exe后,一旦完成或可能超时,它将始终返回到****行,因此作业将对其进行记录。但是,在这种环境下,由于某些未知原因,MyConsole.exe突然消失了。由于这种情况并非总是会发生,因此我们不确定是什么原因/原因。并且在作业日志中,没有A行和B行的日志信息。这使我认为也许作业Execute(IJobExecutionContext上下文)坏了。
在Quartz中有可能吗?我的意思是因为这个或那个原因(也许是内存等),作业的Execute线程突然被Quartz终止了?有办法知道吗?是否有办法在发生这种情况时将其捕获?也许需要在配置中打开一些设置?
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)