如何在c#中停止当前正在运行的进程,或者如何使用C#关闭当前正在运行的Internet Explorer进程 [英] How to Stop a Current Running Process in c#, or How to close current Running Internet Explorer Process using C#

查看:622
本文介绍了如何在c#中停止当前正在运行的进程,或者如何使用C#关闭当前正在运行的Internet Explorer进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我开发了一个C#Windows应用程序,在Loaded上执行SQL查询并获取位置纬度和经度。并在消息框中向用户显示值。当用户点击消息框的确定按钮时,将打开Internet Explorer,并且谷歌地图页面将打开纬度和经度对应位置。



For这个工作,我用下面的代码到我的程序: -



  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);





这是完美的工作。



但是我的程序将每5秒执行一次sql查询,如果数据被更改,那么它将再次显示一个新的弹出窗口并打开网站。



现在第二次在Internet Explorer中打开网页时,它会在新标签中打开它。



但是我希望它能打开它在我的现有标签中。或者在执行之前应该关闭现有的打开的Internet Explorer。



请帮帮我。

解决方案

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

// 我发现这比串联更具可读性
string url = String .Format( https://www.google.co.in/maps/place/ {0},{1},lati,longi);

// 将此引用保留在类的成员变量中或以其他方式避免外出范围
流程ie = System.Diagnostics.Process.Start(url);





在下一个你的计时器的勾号是

 ie.Close(); 



开始新流程之前。


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:-

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.

解决方案

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

ie.Close();


before you start new process.


这篇关于如何在c#中停止当前正在运行的进程,或者如何使用C#关闭当前正在运行的Internet Explorer进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆