当前位置: 首页>>代码示例>>C#>>正文


C# Process.CloseMainWindow方法代码示例

本文整理汇总了C#中System.Diagnostics.Process.CloseMainWindow方法的典型用法代码示例。如果您正苦于以下问题:C# Process.CloseMainWindow方法的具体用法?C# Process.CloseMainWindow怎么用?C# Process.CloseMainWindow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.Process的用法示例。


在下文中一共展示了Process.CloseMainWindow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: kill

 public static void kill(Process P,bool force)
 {
     if (!isKilling(P) && P.Id != Process.GetCurrentProcess().Id)
     {
         if (force)
         {
             new frmKill(P).Show();
         }
         else
         {
             try
             {
                 P.CloseMainWindow();
             }
             catch
             {
                 //NOOP
             }
         }
     }
 }
开发者ID:sarciszewski,项目名称:ProcessKiller,代码行数:21,代码来源:Program.cs

示例2: StartIisExpress

        private void StartIisExpress()
        {
            var applicationHostConfig = CreateApplicationHostConfig();

            var applicationHostPath = Path.GetFullPath("applicationHost.config");
            File.WriteAllText(applicationHostPath, applicationHostConfig);

            var startInfo = new ProcessStartInfo
            {
                UseShellExecute = false,
                WindowStyle = ProcessWindowStyle.Minimized,
                CreateNoWindow = !_options.ShowIisExpressWindow,
                Arguments = string.Format("/config:\"{0}\" /systray:true", applicationHostPath)
            };

            var programfiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
            startInfo.FileName = programfiles + "\\IIS Express\\iisexpress.exe";

            try
            {
                _process = new Process { StartInfo = startInfo };

                _process.Start();
                _manualResetEvent.Set();
                _process.WaitForExit();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error starting IIS Express: " + ex);
                _process.CloseMainWindow();
                _process.Dispose();
            }
        }
开发者ID:modulexcite,项目名称:dryrunner,代码行数:33,代码来源:TestSiteServer.cs

示例3: StartIisExpress

        private static void StartIisExpress()
        {
            var startInfo = new ProcessStartInfo
            {
                WindowStyle = ProcessWindowStyle.Normal,
                ErrorDialog = true,
                LoadUserProfile = true,
                CreateNoWindow = false,
                UseShellExecute = false,
                Arguments = string.Format("/config:{0} /site:{1}", @"../../../.vs/config/applicationhost.config", "Web")
            };
            var programfiles = string.IsNullOrEmpty(startInfo.EnvironmentVariables["programfiles"])
                                ? startInfo.EnvironmentVariables["programfiles(x86)"]
                                : startInfo.EnvironmentVariables["programfiles"];

            startInfo.FileName = programfiles + "\\IIS Express\\iisexpress.exe";

            try
            {
                _iisProcess = new Process { StartInfo = startInfo };

                _iisProcess.Start();
                _iisProcess.WaitForExit();
            }
            catch
            {
                _iisProcess.CloseMainWindow();
                _iisProcess.Dispose();
            }
        }
开发者ID:aav7fl,项目名称:GVSU-capstone-project,代码行数:30,代码来源:WebServer.cs

示例4: StartIisExpress

        private static void StartIisExpress()
        {
            var startInfo = new ProcessStartInfo
            {
                WindowStyle = ProcessWindowStyle.Normal,
                ErrorDialog = true,
                LoadUserProfile = true,
                CreateNoWindow = false,
                UseShellExecute = false,
                Arguments = string.Format("/path:\"{0}\" /port:{1}",
                    @"C:\Users\ian\Documents\Visual Studio 2015\Projects\SimpleCalculator\SimpleCalculator",
                    "8888")
            };

            var programfiles = string.IsNullOrEmpty(startInfo.EnvironmentVariables["programfiles"])
                ? startInfo.EnvironmentVariables["programfiles(x86)"]
                : startInfo.EnvironmentVariables["programfiles"];

            startInfo.FileName = programfiles + "\\IIS Express\\iisexpress.exe";

            try
            {
                _iisProcess = new Process { StartInfo = startInfo };
                _iisProcess.Start();
                _iisProcess.WaitForExit();
            }
            catch
            {
                _iisProcess.CloseMainWindow();
                _iisProcess.Dispose();
            }
        }
开发者ID:ianchute,项目名称:SimpleCalculator,代码行数:32,代码来源:WebServer.cs

示例5: StartIisExpress

        private static void StartIisExpress()
        {
            var projectPath = $"{Environment.CurrentDirectory}\\..\\..\\..\\..\\ContosoUniversity.Web.Mvc\\obj\\Publish";
            projectPath = System.IO.Path.GetFullPath(projectPath);

            var startInfo = new ProcessStartInfo
            {
                WindowStyle = ProcessWindowStyle.Normal,
                ErrorDialog = true,
                LoadUserProfile = true,
                CreateNoWindow = false,
                UseShellExecute = false,
                Arguments = string.Format("/path:\"{0}\" /port:{1}", projectPath, Port)
            };

            var programfiles = string.IsNullOrEmpty(startInfo.EnvironmentVariables["programfiles"])
                ? startInfo.EnvironmentVariables["programfiles(x86)"]
                : startInfo.EnvironmentVariables["programfiles"];

            startInfo.FileName = programfiles + "\\IIS Express\\iisexpress.exe";
            try
            {
                _iisProcess = new Process { StartInfo = startInfo };
                _iisProcess.Start();
                _iisProcess.WaitForExit();
            }
            catch
            {
                _iisProcess.CloseMainWindow();
                _iisProcess.Dispose();
            }
        }
开发者ID:extstopcodepls,项目名称:ContosoUniversity,代码行数:32,代码来源:IisExpressHelper.cs

示例6: RunAsync

        public static Task<ProcessResults> RunAsync(ProcessStartInfo processStartInfo, CancellationToken cancellationToken)
        {
            if (processStartInfo == null)
            {
                throw new ArgumentNullException("processStartInfo");
            }

            // force some settings in the start info so we can capture the output
            processStartInfo.UseShellExecute = false;
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.RedirectStandardError = true;
            processStartInfo.CreateNoWindow = true;

            var tcs = new TaskCompletionSource<ProcessResults>();

            var standardOutput = new List<string>();
            var standardError = new List<string>();

            var process = new Process
            {
                StartInfo = processStartInfo,
                EnableRaisingEvents = true,
            };

            process.OutputDataReceived += (sender, args) =>
            {
                if (args.Data != null)
                {
                    standardOutput.Add(args.Data);
                }
            };

            process.ErrorDataReceived += (sender, args) =>
            {
                if (args.Data != null)
                {
                    standardError.Add(args.Data);
                }
            };

            process.Exited += (sender, args) => tcs.TrySetResult(new ProcessResults(process, standardOutput, standardError));

            cancellationToken.Register(() =>
            {
                tcs.TrySetCanceled();
                process.CloseMainWindow();
            });

            cancellationToken.ThrowIfCancellationRequested();

            if (process.Start() == false)
            {
                tcs.TrySetException(new InvalidOperationException("Failed to start process"));
            }

            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            return tcs.Task;
        }
开发者ID:mikecole,项目名称:ChocolateyGUI,代码行数:60,代码来源:ProcessEx.cs

示例7: kill

 private static void kill(Process process)
 {
     process.CloseMainWindow();
     if (!process.HasExited) {
         process.Kill();        
     }
     process.WaitForExit();
     process.Close();
 }
开发者ID:infinispan,项目名称:dotnet-client,代码行数:9,代码来源:PlatformUtils.cs

示例8: CloseApplication

 void CloseApplication(Process process, bool force) {
     int num = force ? 1 : 0x2710;
     DateTime now = DateTime.Now;
     TimeSpan zero = TimeSpan.Zero;
     bool flag = false;
     IntPtr ptr = IntPtr.Zero;
     while (zero.TotalMilliseconds < num){
         Trace.WriteLine(DateTime.Now + "\tCall Process.Refresh() at WinApplicationAdapter.CloseApplication");
         process.Refresh();
         Trace.WriteLine(DateTime.Now + "\tCall Process.Refresh() success");
         Trace.WriteLine(DateTime.Now +"\tCall Process.MainWindowHandle at WinApplicationAdapter.CloseApplication");
         IntPtr mainWindowHandle = IntPtr.Zero;
         try{
             mainWindowHandle = process.MainWindowHandle;
         }
         catch (InvalidOperationException){
         }
         if ((mainWindowHandle != ptr) && (mainWindowHandle != IntPtr.Zero)){
             ptr = mainWindowHandle;
             try{
                 process.CloseMainWindow();
             }
             catch (Exception exception){
                 Logger.Instance.AddMessage(string.Format("Process{0}.CloseMainWindow return error:\n'{1}'",process.ProcessName, exception.Message));
             }
         }
         Trace.WriteLine(DateTime.Now + "\tCall Process.MainWindowHandle success");
         try{
             if (process.WaitForExit(Math.Min(0x3e8, num - ((int) zero.TotalMilliseconds)))){
                 flag = true;
                 break;
             }
         }
         catch (Exception exception2){
             Logger.Instance.AddMessage(string.Format("Process.WaitForExit return error:\n'{0}'",exception2.Message));
         }
         zero = DateTime.Now - now;
     }
     if (!flag){
         if (!force){
             Logger.Instance.AddMessage(string.Format("The process '{0}' was not closed in '{1}' millisecond after the Process.CloseMainWindow was invoked, trying to kill this process",process.ProcessName, num));
         }
         try{
             process.Kill();
         }
         catch (Exception exception3){
             Logger.Instance.AddMessage(string.Format("Process name: '{0}' is not killed.\nReason:\n'{1}'",process.ProcessName, exception3.Message));
         }
         if (!process.WaitForExit(0x2710)){
             throw new WarningException(
                 string.Format("Process name: '{0}' doesn't exited in 10 seconds after the Process.Kill was invoked",process.ProcessName));
         }
     }
 }
开发者ID:aries544,项目名称:eXpand,代码行数:54,代码来源:XpandTestWinAdapter.cs

示例9: SendCloseMessage

        public static void SendCloseMessage(Process process)
        {
            if(process.MainWindowHandle != IntPtr.Zero)
            {
                process.CloseMainWindow();
            }

            foreach (ProcessThread pt in process.Threads)
            {
                EnumThreadWindows((uint)pt.Id, EnumThreadCallback, IntPtr.Zero);
            }
        }
开发者ID:MCord,项目名称:WarmDelete,代码行数:12,代码来源:Messenger.cs

示例10: Start

 public void Start()
 {
     try
     {
         Console.WriteLine("Launching IIS Express: {0} {1}", _startInfo.FileName, _startInfo.Arguments);
         IisProcess = Process.Start(_startInfo);
     }
     catch
     {
         IisProcess.CloseMainWindow();
         IisProcess.Dispose();
     }
 }
开发者ID:rskulles,项目名称:roadkill,代码行数:13,代码来源:IISExpress.cs

示例11: Main

        static void Main(string[] args)
        {
            var bdir = AppDomain.CurrentDomain.BaseDirectory;
            var param = "/c "+"java -jar " + bdir + "sat4j-pb.jar " + bdir + "generatedForVideoTutorial.opb > c:\\myou.txt";
            var processStartInfo = new ProcessStartInfo(@"cmd.exe", param)
            {
                UseShellExecute = true,
                RedirectStandardOutput = false,
                RedirectStandardInput = false,
                CreateNoWindow = false,
                WindowStyle = ProcessWindowStyle.Minimized
            };

            _cmdExe = new Process { StartInfo = processStartInfo, EnableRaisingEvents = true };
            _cmdExe.Start();

            StartTime = DateTime.Now;
            while (true)
            {
                CurrentTime = DateTime.Now;
                var diff = CurrentTime.Subtract(StartTime).TotalSeconds;
                if (diff >= 10)
                {
                    try
                    {
                        SendCtrlC(_cmdExe.MainWindowHandle);
                    }
                    catch (Exception exception)
                    {
                        _cmdExe.CloseMainWindow();
                        throw;
                    }
                    _cmdExe.CloseMainWindow();
                    break;
                }
            }
        }
开发者ID:kolokolca,项目名称:Searistica,代码行数:37,代码来源:Program.cs

示例12: KillProcess

            public virtual void KillProcess(Process p, bool gracefully = false) {
                Contract.Requires<ArgumentNullException>(p != null);
                if (gracefully) {
                    p.CloseMainWindow();
                    var i = 0;
                    while (!p.SafeHasExited()) {
                        i++;
                        if (i > 4)
                            break;
                        Thread.Sleep(1000);
                    }
                }

                if (!p.SafeHasExited())
                    p.Kill();
            }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:16,代码来源:Processes.cs

示例13: Main

        static void Main(string[] args)
        {
            Process processClient = new Process();

            processClient.StartInfo.FileName = "ProcessClient.exe";
            processClient.StartInfo.UseShellExecute = true; // musts be true
            processClient.Start();

            Thread.Sleep(2000);
            processClient.CloseMainWindow();

            processClient.WaitForExit();
            processClient.Close();
            LogIt("Client quit. Server terminating.");
            Console.ReadKey();
        }
开发者ID:bashocz,项目名称:Examples,代码行数:16,代码来源:ProcessServer.cs

示例14: frmKill

 public frmKill(Process Proc)
 {
     //prevents deleting of the referenced object
     P = Process.GetProcessById(Proc.Id);
     InitializeComponent();
     try
     {
         P.CloseMainWindow();
     }
     catch
     {
         //There is no Window to close wo we kill it instantly.
         i = MAXWAIT;
     }
     tKill.Start();
     label1.Text = "Killing PID: " + P.Id.ToString();
 }
开发者ID:sarciszewski,项目名称:ProcessKiller,代码行数:17,代码来源:frmKill.cs

示例15: ExecuteTask

		protected override void ExecuteTask()
		{
			outputPathForExec = exec.Output;
			FileManager.CreateFileIfNotExists(exec.Output);
			using (Process process = new Process())
			{
				if (String.IsNullOrEmpty(exec.WorkingDirect))
				{
					process.StartInfo.WorkingDirectory = PackageManagerWorkspace.PackagePath;
				}
				else
				{
					FileManager.CreateDirectoryIfNotExists(exec.WorkingDirect);
					process.StartInfo.WorkingDirectory = exec.WorkingDirect;
				}
				process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
				process.StartInfo.FileName = string.IsNullOrEmpty(exec.BaseDirectory)
					? exec.Program
					: Path.Combine(PackageManagerWorkspace.PackagePath, exec.BaseDirectory, exec.Program);
				;
				process.StartInfo.Arguments = exec.CommandLine;
				process.StartInfo.UseShellExecute = false;
				process.StartInfo.RedirectStandardOutput = true;
				process.StartInfo.RedirectStandardError = true;
				process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
				process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
				process.Start();
				if (exec.Timeout > 0)
				{
					process.WaitForExit(exec.Timeout);
					if (process.HasExited == false)
					{
						if (process.Responding)
							process.CloseMainWindow();
						else
							process.Kill();

						throw new TimeoutException("TimeOut program execution: " + exec.Program);
					}
				}
				else
				{
					process.WaitForExit();
				}
			}
		}
开发者ID:egormozzharov,项目名称:packageManager,代码行数:46,代码来源:ExecTask.cs


注:本文中的System.Diagnostics.Process.CloseMainWindow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。