久久久久久久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 的類)
主站蜘蛛池模板: 日韩欧美一区在线 | 中文字幕 在线观看 | 福利社午夜影院 | 五月天激情综合网 | 欧美视频成人 | 欧美国产精品久久久 | 国产99精品 | 黄色a视频| 亚洲永久免费观看 | 久久免费视频2 | 91极品欧美视频 | 久久91精品国产一区二区三区 | 337p日本欧洲亚洲大胆鲁鲁 | 呦呦在线视频 | 日韩欧美一区二区三区 | 亚洲一区二区免费视频 | www.五月天婷婷.com | 91欧美精品成人综合在线观看 | 蜜桃一区二区三区 | 精品福利视频一区二区三区 | 国产精品.xx视频.xxtv | 男人天堂999 | 午夜影院在线观看 | 国产精品久久国产精品 | 国产japanhdxxxx麻豆 | 国产特级毛片 | 国产精品18毛片一区二区 | 懂色av一区二区三区在线播放 | 成人a视频片观看免费 | 色婷婷av久久久久久久 | 97精品超碰一区二区三区 | 国产精品视频在线观看 | 成人欧美一区二区三区在线播放 | 成人a免费 | 久久看精品 | 国产精品久久久久久久模特 | 涩涩导航 | 日本在线视频一区二区 | 精品久久久久久久久久 | 毛片网站在线观看 | 午夜欧美一区二区三区在线播放 |