How to run Outlook using Process.Start(“outlook.exe”) and get the control back

前端 未结 5 845
难免孤独
难免孤独 2021-01-26 15:42

My C# program needs to launch Office Outlook and get the current \"running outlook application\". In order to do that I\'ve implemented the following simple program (so if you w

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-26 16:24

    MAYBE the process need some time to start.

    Try this:

      if (Process.GetProcessesByName("OUTLOOK").Count().Equals(0))
      {
        Process.Start("outlook.exe"); // MY PROGRAM STOPS HERE
      }
    
      while ((Process.GetProcessesByName("OUTLOOK").Count().Equals(0));
    
      var process = Process.GetProcessesByName("OUTLOOK").First();
    

    This should cause starting process and waiting until it is avaible before trying to catch it...

提交回复
热议问题