久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Waitforexit 統一中斷我正在運行的應用程序

Waitforexit interrupt my running application in unity(Waitforexit 統一中斷我正在運行的應用程序)
本文介紹了Waitforexit 統一中斷我正在運行的應用程序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試統一運行 exe 應用程序以執行某些功能,并且該 exe 文件在統一運行時將從我的麥克風獲取輸入,因此我必須等到它退出,而使用 waitforexit 允許 exe 接受輸入很好但這并不好,因為我在 exe 運行期間的統一應用程序會停止,直到我的 exe 完成,我想在我的 exe 運行時統一執行其他操作.

I'm trying to run an exe application in unity to perform some function and that exe file will take an input from my microphone when running in unity so i must wait until it exit while using waitforexit is nice to allow exe takes input but it's not good because my unity app during the exe running becomes stopped till it my exe finish and i want perform somethings else in unity while my exe running.

這是我的代碼:-

System.Diagnostics.Process p = new System.Diagnostics.Process();

System.Diagnostics.Process p = new System.Diagnostics.Process();

    p.StartInfo = new System.Diagnostics.ProcessStartInfo("E:\app\dist\app.exe");
    p.StartInfo.WorkingDirectory = @"Assets\app\dist\app.exe";
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    p.Start();
    p.WaitForExit();

推薦答案

你不必使用 WaitForExit 因為它阻塞了主線程.您的問題有兩種解決方法:

You don't have to use WaitForExit since it's blocking the main Thread. There are two workarounds for your issue:

1.將 EnableRaisingEvents 設置為 true.訂閱 Exited 事件并使用它來確定打開的程序何時關閉.在 Update 函數中使用布爾標志來確定它是否仍處于打開狀態.

1.Set EnableRaisingEvents to true. Subscribe to the Exited event and use that to determine when the opened program has closed. Use a boolean flag to determine if it is still opened or not in the Update function.

bool processing = false;

void Start()
{
    processing = true;

    Process p = new Process(); ;
    p.StartInfo = new System.Diagnostics.ProcessStartInfo("E:\app\dist\app.exe");
    p.StartInfo.WorkingDirectory = @"Assets\app\dist\app.exe";
    p.StartInfo.CreateNoWindow = true;
    p.EnableRaisingEvents = true;
    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    p.Exited += new EventHandler(OnProcessExit);
    p.Start();
}

private void OnProcessExit(object sender, EventArgs e)
{
    processing = false;
}


void Update()
{
    if (processing)
    {
        //Still processing. Keep reading....
    }
}

<小時>

2.繼續使用您的 WaitForExit 只在新的 Thread 中使用該代碼,這樣它就不會'不阻塞或凍結 Unity 的主線程.


2.Continue with your WaitForExit but only use that code in a new Thread so that it doesn't block or freeze Unity's main Thread.

//Create Thread
Thread thread = new Thread(delegate ()
{
    //Execute in a new Thread
    Process p = new Process(); ;
    p.StartInfo = new System.Diagnostics.ProcessStartInfo("E:\app\dist\app.exe");
    p.StartInfo.WorkingDirectory = @"Assets\app\dist\app.exe";
    p.StartInfo.CreateNoWindow = true;
    p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    p.Start();
    p.WaitForExit();

    //....
});
//Start the Thread and execute the code inside it
thread.Start();

請注意,您不能在這個新線程中使用 Unity 的 API.如果您想這樣做,請使用 UnityThread.executeInUpdate.請參閱 這個了解更多信息.

Note that you can't use Unity's API from this new Thread. If you want to do so, use UnityThread.executeInUpdate. See this for more information.

這篇關于Waitforexit 統一中斷我正在運行的應用程序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is there a C# library that will perform the Excel NORMINV function?(是否有執行 Excel NORMINV 函數的 C# 庫?)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權列表中選擇 x 個隨機元素(無需替換))
Create a summary description of a schedule given a list of shifts(給定輪班列表,創建時間表的摘要描述)
C# Normal Random Number(C# 普通隨機數)
Standard deviation of generic list?(通用列表的標準偏差?)
AsyncCTP: Creating a class that is IAwaitable(AsyncCTP:創建一個 IAwaitable 的類)
主站蜘蛛池模板: 东方成人av | 午夜快播 | 91久久综合亚洲鲁鲁五月天 | 黄色福利 | 色片网址 | 国产一区二区视频在线 | 久久草av| 亚洲综合日韩 | 国产精品久久久国产盗摄 | 手机看片福利视频 | 四虎影视库 | 日韩午夜在线观看 | 国产性色av| 五月婷婷激情 | 日本黄色视屏 | 中文字幕超清在线观看 | 美女免费视频网站 | 91少妇丨porny丨| 最新av在线播放 | 天天色天天干天天 | 欧美一级黄色片 | av网址在线免费观看 | av网站免费观看 | 成人免费视频国产免费 | 久久成人免费视频 | 一区二区三区四区在线播放 | 国产精品成人一区 | 精品黄色片 | 怡红院亚洲 | 久久久久久一区二区 | 亚洲综合图片区 | 欧美国产激情 | 亚洲久久久| 手机福利视频 | 久久艹国产 | 成年网站在线观看 | 一级做a爱片性色毛片 | 国产欧美综合一区二区三区 | 国产成人免费在线观看 | 国产精品99精品久久免费 | 色吧五月天 |