?
Solved

System.Diagnostics.Process - close browser window

Posted on 2005-04-14
10
Medium Priority
?
2,160 Views
Last Modified: 2008-01-09
Hey!

I have a Windows Application with a button.
The event looks like:

System.Diagnostics.Process proces = new System.Diagnostics.Process();
proces.StartInfo.FileName = "http://localhost/nwind/template/testUpdategram.xml";
proces.StartInfo.CreateNoWindow = true;
proces.Start();
proces.Close();

When the process is finished I want to close browser window.
Why is my browser still open?

Thanks in advance!

melack
0
Comment
Question by:Maddogslo
  • 5
  • 3
  • 2
10 Comments
 
LVL 11

Expert Comment

by:Agarici
ID: 13780042
you should use a process.waitforexit() after the call to close

if close does not work try process.closemainwindow
if that doesn't work either, try prcess.kill.

hth,
A.
0
 
LVL 2

Expert Comment

by:Mohammad Aamir Qureshi
ID: 13780664
Wellll

Kill the Process

process.Kill();       //// check this
0
 

Author Comment

by:Maddogslo
ID: 13780900
I tryed all possibilities :

( System.Diagnostics.Process proces = new System.Diagnostics.Process();
  proces.StartInfo.FileName = "http://localhost/nwind/template/testUpdategram.xml";
  proces.Start();
  proces.Kill();
  proces.WaitForExit();
)

and I get this error:

System.InvalidOperationException: No process is associated with this object.

Any clues?


melack


0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 11

Accepted Solution

by:
Agarici earned 1000 total points
ID: 13780927
you have to wait a litle for the process to start
i think you call kill before the process finished starting

so, do a thred.sleep(1000) before killing the process

hth,
A.
0
 

Author Comment

by:Maddogslo
ID: 13781145
I tryed with Thread.sleep(1000).
The thing is:

1) System.Diagnostics.Process proces = new System.Diagnostics.Process();
proces.StartInfo.FileName = "http://localhost/nwind/template/testUpdategram.xml";
proces.Start();
proces.Close();

->No error is displayed but browser is still opened.


2)- if I add proces.Kill()  or
   - Thread.Sleep(2000)
      proces.Kill();

-> I get this error: System.InvalidOperationException: No process is associated with this object.


Don't know what it could be... I appreciate any help.

melack
0
 
LVL 11

Expert Comment

by:Agarici
ID: 13781171
can you do something like putting a button  on the window and on that button pressed call process.kill? so you can call kill after you have seen the ie window appearing
0
 

Author Comment

by:Maddogslo
ID: 13781330
I did like you said but with no effect. I get the same exception.
May be I'm using the wrong approach.

I want to execute an URI in a browser. More specific I want to call an Updategram.xml file (for example: http://localhost/nwind/template/testUpdategram.xml)
but I need to do it programmatically.

So I used a process. Is there another way?

melack
0
 

Author Comment

by:Maddogslo
ID: 13781860
I found an interesting way to solve my problem!
Instead of killing the process I hide the browser window.

Process p = new Process();
p.StartInfo.FileName = "iexplore.exe";
p.StartInfo.Arguments = "http://localhost/nwind/template/testUpdategram.xml";
---------------------------------------------------------------------------------------
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
---------------------------------------------------------------------------------------
p.Start();
p.Close();


melack
0
 
LVL 2

Expert Comment

by:Mohammad Aamir Qureshi
ID: 13796374
When u use Hidden  property it invisible from u but it still runnig and consume memory

ok

let check this then tell me this is for paractice may ba u understand it

static Process p = new Process();   // declare above the main

drag and drop two buttons name start and stop .
on start button click event  write down your code
and in stop button click event u simply kill the process
p.Kill();

simply check this then tell to me
0
 

Author Comment

by:Maddogslo
ID: 13798127
Hey, Aamirg!

I tryed the practice and it works.
Next, I put this code in a single button event:

p.StartInfo.FileName = "iexplore.exe";
p.StartInfo.Arguments = "http://localhost/nwind/template/testUpdategram.xml";
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.Start();
Thread.Sleep(2000);
p.Kill();

Thanks for your help!

melack
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question