Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

C#
         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);
             }
            
         }
Posted
Updated 11-Nov-11 20:19pm
v2
Comments
Sergey Alexandrovich Kryukov 13-Nov-11 9:45am    
Creating a new process is a disaster, by not clear what's the problem. What does it mean, "show existing process"? Yes, I can guess, but this is not a question.
--SA

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900