Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I developed an C# Windows Application which on Loaded will execute an SQL Query and get the Location Latitude and Longitudes. And displays the values to the user in a message Box. When a user clicks on OK button of the Message Box then Internet Explorer will be opened and the Google Maps page will get opened with the Latitude and Longitude Corresponding Location.

For this to work, i have used the below line to my Program:-

C#
string lati = reader.GetValue(1).ToString();
string longi = reader.GetValue(2).ToString();
string url1 = "https://www.google.co.in/maps/place/";
string url = url1 + lati + "," + longi;
System.Diagnostics.Process.Start(url);


This is working Perfectly.

But my program will execute the sql query for every 5 Seconds, If the data is changed then it will again display a new popup and open the website.

Now second time when it is opening the Webpage in Internet Explorer, it is opening it in new Tab.

But i want it to opened it in my Existing Tab. or the Existing opened Internet Explorer should be closed before executing.

Please help me with this.
Posted
Comments
Krishna Chaitanya Bezawada 20-May-15 1:12am    
I know that we can keep an option in the Internet Explorer settings, to open an request from an application in the current Tab. But i want to know is there any process to kill the current running Process directly from c# application.

As we called a process like "system.Diagnostics.process.start(url)"
like wise is there any code to stop that process?
Sinisa Hajnal 20-May-15 2:42am    
Process.Start returns a reference to started process. You have to simply keep the reference and update processinfo with your url. Not sure about refreshing though. Even if you cannot refresh it while running, you can stop it by calling process.Close and start new instance.

1 solution

C#
string lati = reader.GetValue(1).ToString();
string longi = reader.GetValue(2).ToString();

// I find this much more readable then concatenation
string url = String.Format("https://www.google.co.in/maps/place/{0},{1}", lati, longi);

// keep this reference in member variable of the class or otherwise keep it from going out of scope
Process ie = System.Diagnostics.Process.Start(url);


On the next tick of your timer do
C#
ie.Close();

before you start new process.
 
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