【问题标题】:How to restart a NativeProcess in adobe air desktop application?如何在 adobe air 桌面应用程序中重新启动 NativeProcess?
【发布时间】:2017-06-12 13:02:01
【问题描述】:

我正在从我们的 adobe air 应用程序运行一个 .net .exe 文件。 .exe 文件接收不同的参数。因此,当我必须发送新参数时,我会停止该过程并使用新参数重新开始。我正在使用 NativeProcess 的 exit() 方法,但是当我再次启动 exe 时,它​​给了我

错误:错误 #3213:无法对已运行的 NativeProcess 执行操作。 在错误$/throwError() 在 flash.desktop::NativeProcess/start()

我已将 nativeProcess 初始化为静态变量:

public  static var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
public static var process:NativeProcess = new NativeProcess();

然后在点击事件中我调用了 exe 文件

var file:File = File.desktopDirectory;
file = file.resolvePath("C:\\somepath.exe");
var ar:Vector.<String> = new Vector.<String>();
ar.push("0");
ar.push("C:\\temp\\APIData.xml");

nativeProcessStartupInfo.executable = file;
nativeProcessStartupInfo.arguments = ar;
process.start(nativeProcessStartupInfo);

这绝对可以正常运行代码。在另一个点击事件中,我调用了

process.exit()

然后再次运行exe

var file:File = File.desktopDirectory;
file = file.resolvePath("C:\\somepath.exe");
var ar:Vector.<String> = new Vector.<String>();
ar.push("1");
ar.push("C:\\temp\\APIData.xml");

nativeProcessStartupInfo.executable = file;
nativeProcessStartupInfo.arguments = ar;
process.start(nativeProcessStartupInfo);

但是在另一个点击事件中,我得到 NativeProcess 已经在运行的错误。有人可以帮我做错什么吗?

【问题讨论】:

    标签: flash apache-flex air adobe


    【解决方案1】:

    如果您在退出后立即重新启动进程,则退出可能需要更长的时间并且该进程尚未“退出”。

    尝试监听进程真正结束时派发的退出事件,然后重新启动进程:

    process.addEventListener(NativeProcessExitEvent.EXIT, onProcessExit);
    
    private function onProcessExit(e:NativeProcessExitEvent):void
    {
        // restart your process from here
    }
    

    当您调用 exit() 时,不能保证进程会结束,因为它发生在 flash 范围之外。作为最后的手段,您可以尝试强制进程退出:

    process.exit(true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多