• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2204
  • Last Modified:

System.Diagnostics.Process - close browser window

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
Maddogslo
Asked:
Maddogslo
  • 5
  • 3
  • 2
1 Solution
 
AgariciCommented:
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
 
Mohammad Aamir QureshiCommented:
Wellll

Kill the Process

process.Kill();       //// check this
0
 
MaddogsloAuthor Commented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
AgariciCommented:
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
 
MaddogsloAuthor Commented:
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
 
AgariciCommented:
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
 
MaddogsloAuthor Commented:
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
 
MaddogsloAuthor Commented:
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
 
Mohammad Aamir QureshiCommented:
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
 
MaddogsloAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now