知道第三方应用程序何时弹出错误屏幕 [英] Know when 3rd party app pops an error screen

查看:60
本文介绍了知道第三方应用程序何时弹出错误屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个调度程序(C#),它使用以下方法执行第三方应用程序。有时第三方应用会弹出一个错误窗口,一切都会被卡住,直到有人确认错误为止。我想知道是否有一种方法可以在C#中看到它。



I have a scheduler (C#) that executes 3rd party apps using the method below. Sometimes the 3rd party app pops an error window and everything gets stuck till somebody acknowledges the error. I want to know if there is a way to see in C# when it happens.

private Process Shell(string AppName, string Arguments, ProcessWindowStyle WindowStyle)
{
   if (!File.Exists(AppName.Replace("\"", "")))
   {
      globError = "Executable: " + AppName + " not found!";
      return null;
   }
   procError = "";
   ProcessStartInfo startInfo = new ProcessStartInfo(AppName);
   startInfo.WindowStyle = WindowStyle;
   startInfo.Arguments = Arguments;
   Process process = new Process();
   process.StartInfo.UseShellExecute = false;
   process.StartInfo.RedirectStandardError = true;
   process.StartInfo = startInfo;
   try
   {
      process.Start();
      return process;
   }
   catch (Exception ex)
   {
      procError = ex.Message;
      return process;
   }
}





我的尝试:





What I have tried:

foreach (Process proc in Process.GetProcesses())
{
   if (thisID > 0 && proc.Id != thisID && proc.Id != ExecutedProcess.Id)
   {
      //Not the process we started or the scheduler process
      if (proc.MainWindowTitle.Length > 8 && ExecutedProcess.MainWindowTitle.Length > 8)
      {
         if (proc.MainWindowTitle.Substring(0, 8) == ExecutedProcess.MainWindowTitle.Substring(0, 8))
         {
            //Another window starting with the same title
            msg = "Another: ID = " + proc.Id.ToString() + " - " + proc.MainWindowTitle;
            WriteLog(CurrTask, msg);
            //Restart(ExecutedProcess, CurrTask, "Error: Another window found - restarting myself", proc);
         }
      }
   }
}



但这有时会返回一个实际上属于带有窗口标题但没有可见窗口的正在运行的进程。


But this sometimes returns a process that is actually part of the running process with a window title, but no visible window.

推荐答案

问题是您必须不断轮询窗口。这使你无法从结果中获取数据。



如果正在执行的应用程序没有显示窗口,可能会更好命令行开关它支持静音模式?如果不支持此功能,请与供应商联系并申请。



或者,如果您可以控制该应用的代码,请删除错误对话框或添加对静音开关的支持。
The problem is that you have to poll constantly for the windows. That takes you away from being able to get the data from the result.

It would be much better if the app being executed didn't show windows, perhaps with a command line switch it supports for "silent" mode? If there isn't support for this, contact the vendor for the app and request it.

Or, if you have control of the code of that app, either remove the error dialogs or add support for the silent switch.


这篇关于知道第三方应用程序何时弹出错误屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆