Язык программирования C#9 и платформа .NET5 - Джепикс Филипп - Страница 274
- Предыдущая
- 274/642
- Следующая
Изменить размер шрифта:
274
} catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } // Уничтожить процесс по нажатию <Enter>. Console.Write("--> Hit enter to kill {0}...", proc.ProcessName); Console.ReadLine(); // Уничтожить все процессы msedge.exe. try { foreach (var p in Process.GetProcessesByName("MsEdge")) { p.Kill(true); } } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); }}Статический метод
Process.Start()Start()В результате вызова метода
Start()Kill()Start()Kill()try/catchInvalidOperationExceptionKill()Kill()На заметку! В .NET Framework (до выхода .NET Core) для запуска процесса методу
Process.Start()msedgeProcessStartInfoУправление запуском процесса с использованием класса ProcessStartInfo
Метод
Process.Start()System.Diagnostics.ProcessStartInfoProcessStartInfopublic sealed class ProcessStartInfo : object{ public ProcessStartInfo(); public ProcessStartInfo(string fileName); public ProcessStartInfo(string fileName, string arguments); public string Arguments { get; set; } public bool CreateNoWindow { get; set; } public StringDictionary EnvironmentVariables { get; } public bool ErrorDialog { get; set; } public IntPtr ErrorDialogParentHandle { get; set; } public string FileName { get; set; } public bool LoadUserProfile { get; set; } public SecureString Password { get; set; } public bool RedirectStandardError { get; set; } public bool RedirectStandardInput { get; set; } public bool RedirectStandardOutput { get; set; } public Encoding StandardErrorEncoding { get; set; } public Encoding StandardOutputEncoding { get; set; } public bool UseShellExecute { get; set; } public string Verb { get; set; } public string[] Verbs { get; } public ProcessWindowStyle WindowStyle { get; set; } public string WorkingDirectory { get; set; }}Чтобы опробовать настройку запуска процесса, модифицируйте метод
StartAndKillProcess()www.facebook.comMsEdgestatic void StartAndKillProcess(){ Process proc = null; // Запустить Microsoft Edge и перейти на сайт Facebook // с развернутым на весь экран окном. try { ProcessStartInfo startInfo = new ProcessStartInfo("MsEdge", "www.facebook.com"); startInfo.UseShellExecute = true; proc = Process.Start(startInfo); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } ...}
274
- Предыдущая
- 274/642
- Следующая
Перейти на страницу:
