簡體   English   中英

System.Windows.Forms.Application'不包含'ExecutablePath的定義

[英]System.Windows.Forms.Application' does not contain a definition for 'ExecutablePath

我正在使用Compact Framework 3.5構建Windows Mobile應用程序。我需要在保存應用程序設置后重新啟動應用程序。 我嘗試了以下方法,從如何重新啟動C#WinForm應用程序?

   string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
Process.Start(path, "");

我沒有收到任何錯誤,但是我的應用程序沒有重新啟動。我正在簽入模擬器。請在移動模擬器中重新開始工作。

需要解決此問題的解決方案。

謝謝

嘗試使用以下代碼訪問路徑:

string path;
path = System.IO.Path.GetDirectoryName(
    System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

但是要重新啟動應用程序,可以使用RunAppAtTime方法:

var time = DateTime.Now.AddSeconds(3); // immediate restart
Notify.RunAppAtTime(thisName, time);   // restart the app

請注意,盡管時間從現在開始設置為3秒,它將立即重新啟動。 要真正延遲,時間差必須大於10秒。 此處的更多信息: https : //stackoverflow.com/a/6133136/3330348

.net應用程序無法自行重啟。 由於它在Mobile上運行,因此框架僅確保一個實例,如果您已將Windows CE作為目標,則可以運行多個實例。

因此,RunAppAtTime是一個很好的解決方案,它允許應用程序本身在使用Application.Exit()終止后由移動調度程序啟動。

另一個選擇是從Application.Exit()啟動的第二個應用程序,監視進程列表以查看主應用程序何時終止(或使用GetProcessExitCode),然后啟動主應用程序的新實例。 此技術用於更新程序等。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM