2010-11-23 31 views

回答

4

如果你問如何在後臺啓動進程(讓你的UI不凍結),你可以寫

ThreadPool.QueueUserWorkItem(delegate { Process.Start("notepad.exe"); }); 

如果你問執行過程在你的進程空間中,對於任意程序來說這是完全不可能的,對於被管理的程序來說這是一個非常糟糕的主意。

0

http://msdn.microsoft.com/en-us/library/e8zac0ca(v=VS.90).aspx

直出MSDN文檔

 Process myProcess = new Process(); 

     try 
     { 
      myProcess.StartInfo.UseShellExecute = false; 
      // You can start any process, HelloWorld is a do-nothing example. 
      myProcess.StartInfo.FileName = "C:\\HelloWorld.exe"; 
      myProcess.StartInfo.CreateNoWindow = true; 
      myProcess.Start(); 
      // This code assumes the process you are starting will terminate itself. 
      // Given that is is started without a window so you cannot terminate it 
      // on the desktop, it must terminate itself or you can do it programmatically 
      // from this application using the Kill method. 
     } 
     catch (Exception e) 
     { 
      Console.WriteLine(e.Message); 
     } 

的那是什麼意思?

+0

我懷疑(希望?)不。 – SLaks 2010-11-23 01:23:06

1

本質上,可執行文件必須運行在它自己的進程中。但是,您可以從可執行文件中的另一個線程啓動一個方法,因爲它本身只是一個程序集。

線程共享創建它的進程的地址空間;進程有自己的地址。

要做到這一點,你需要使被引用的exe文件爲friend assembly。見here

或使用remoting

3

如果從另一個線程啓動另一個可執行文件,則將啓動一個新進程。我認爲你有點混淆線程,進程和可執行文件之間的關係。

相關問題