tags:

views:

36

answers:

4

Hi,

I have an application which generates a .pdf file and open it using myProcess.start(pdfFileName); . This called is called in the event handler of a click event on a button in a Winfom app.

Everything works fine, except that if I quit (alt-f4 or using the top-right cross) my application after Acrobat Reader have been started, my application do not stop : the Form disapears, but the debugging session in VS do not stop, even if I have already quit Acrobat Reader. The beahaviour is the same if I compile in realese and/or start the exe from windows and not from VS, I then have to kill the process with the task manager.

I could find nothing in the documentation, but I understand this must be a very common problem ?

Thanks, Jaune.

+2  A: 

You need to hook the ProcessExit event

myProcess.StartInfo.FileName = fileName;
myProcess.EnableRaisingEvents = true;
myProcess.Exited += new EventHandler(myProcess_Exited);
myProcess.Start();

[...]

private void myProcess_Exited(object sender, System.EventArgs e) {
  Application.Exit();
}
Preet Sangha
Ok, thanks you.So there is no way to just start a process which is not bound to my process. Since the user may launch open an unknown number of pdf, I have to count the process and use event-handler to know when they are all terminated before I can Exit() ?
Jaunedeau
A: 

In the section of your code that runs when the app is shutdown, for example an on exit event you could kill the process. See http://msdn.microsoft.com/en-us/library/05abh773(v=vs.71).aspx

Shiraz Bhaiji
I do not want to kill the Acrobat processes when my application exits :)
Jaunedeau
A: 

I just tested it, with Acrobat reader as well, and the application exits normally. You must have left a background process or thread(s) running in a loop.

Ruel
You seem to be right : I made a new WinForm Application, just added on button to it, and in set this method as the handler for the click : private void button1_Click(object sender, EventArgs e) { Process process = new Process(); Process.Start(@"c:\a.pdf"); }And this works correctly. So maybe the issue comes from the XSL:FO transformer (nFop, java port). I will try to dig there and update if I found the answer. Thanks you.
Jaunedeau
Alright, Good luck!
Ruel
A: 
theProcess.EnableRaisingEvents = true;
theProcess.Exited +=  delegate(object sender, System.EventArgs e)
                                    { Application.Exit();  }
theProcess.Start();
mumtaz