国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

在C#中啟動另一個程序的實現方法

2023-05-18 12:33:08
字體:
來源:轉載
供稿:網友

在本網站中曾經探討過在C#程序中啟動外部程序的方法,在這里有另一種方法同樣可以啟動外部的程序。

程序的目的是使用C#實現啟動另一程序的方法。技術總監給出了我們這樣一個有效的啟動程序的有效方法,大家分享下:

 

以下是引用片段:
  private void btnCreate_Click(object sender, EventArgs e)
  ...{
  int hWnd = FindWindow(null, "test");//窗體的名稱
  //check if PowerReuse is launched or not
  //if yes, pass path of project to PowerReuse
  //or, launch PowerReuse with specified parameter
  if (hWnd > 0)
  ...{
  MessageBox.Show("powerReuse has been launched already." + " " + hWnd.ToString());
  //SendMessage to PowerReuse
  return;
  }
  try
  ...{
  Process Main_P = new Process();
  //this path should be retrieved from Windows Registry,
  //the loaction is written by Installter during process of installation.
  Main_P.StartInfo.FileName = @"C: est.exe";//運行的exe路徑
  //This URL is passed to PowerReuse to open
  Main_P.StartInfo.Arguments = @"C:Tempabc.prj";//運行時的參數
  Main_P.StartInfo.UseShellExecute = true;
  Main_P.Start();
  //
  //we have to wait for a while until UI has been initialized
  //
  Main_P.WaitForInputIdle(10000);
  //although UI has been initialzied,
  //it does not mean main form of application has been completed.
  //we may wait for another 10 seconds
  for (int i = 0; i < 100; i++)
  ...{
  hWnd = FindWindow(null, "PowerReuse (Beta)");
  //hWnd = Main_P.MainWindowHandle.ToInt32() ;
  if (hWnd > 0) break;
  Thread.Sleep(100);
  }
  //Here, we check if PowerReuse is fully launched
  if (hWnd == 0)
  ...{
  //Handle exception
  MessageBox.Show("We cannot find window handle of PowerReuse");
  }
  else
  ...{
  //other handling
  //
  MessageBox.Show(hWnd.ToString() + " " + Main_P.MainWindowHandle.ToString() + " " + Main_P.MainWindowTitle);
  }
  }
  catch (Exception ex)
  ...{
  MessageBox.Show(ex.Message);
  }
  }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贺兰县| 双流县| 怀来县| 桐柏县| 东方市| 和平县| 松阳县| 会泽县| 泉州市| 绍兴县| 雷山县| 嵩明县| 临武县| 祁门县| 乐都县| 雅安市| 上饶县| 佛坪县| 遂宁市| 蕉岭县| 凤阳县| 梁平县| 司法| 隆林| 砀山县| 蒙山县| 类乌齐县| 石城县| 新余市| 石屏县| 察隅县| 科尔| 临汾市| 汶川县| 镇沅| 焦作市| 长沙县| 永济市| 阿勒泰市| 大渡口区| 宿迁市|