如何在C#.net中显示现有过程而不是创建新过程 [英] How to show existing process instead of creating new process in c# .net

查看:82
本文介绍了如何在C#.net中显示现有过程而不是创建新过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我有两个问题,我正在使用c#
1.如何在菜单单击事件中显示现有(运行)过程而不是创建新过程

2.如何关闭应用程序中所有正在运行的进程

我正在调用chm文件以在应用程序中显示帮助窗口.

但是我的应用程序正在为每个菜单单击事件创建一个新进程,并且它仅关闭一个进程,而不是关闭所有进程

这是我的代码,请对此进行更正.

hello everybody
i have two problems and i am using c#
1. How to show existing (running )process instead of create new process in menu click event

2. how to close all running process in my application

I am calling the chm file to show help window in my application.

But My application doing create new process for every menu click event and it close only the one process not all process

this is my code please correct this.

         ProcessStartInfo psi;
         Process p;
         string prcpath = @"D:\Myproject\testhelp.chm";

          private void mnuOnScreen_Click(object sender, EventArgs e)
         {
              psi = new ProcessStartInfo(prcpath);
                 p = Process.Start(psi);
                 MessageBox.Show("New process created");
                
             }

//code for close process

private void FrmTRMS_FormClosing(object sender, FormClosingEventArgs e)
         {
            
             try
             {
                 if (p.HasExited)
                   {

                       p.CloseMainWindow();

                   }
                   else
                   {
                       p.Kill();
                   }
                
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
            
         }

推荐答案

因此,每次单击菜单都会启动一个新过程吗?这不是一个很好的设计.已经有一种方法可以在.net中显示帮助文件

http://msdn.microsoft.com/en-us/library/system.windows.forms.help.showhelp.aspx [ ^ ]
So every time the menu is clicked you start a new process? This is not a very good design. There is already a method to show help files in .net

http://msdn.microsoft.com/en-us/library/system.windows.forms.help.showhelp.aspx[^]


这篇关于如何在C#.net中显示现有过程而不是创建新过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆