C# ping问题,再次求救!!!

gaoxing_1985007 2010-09-20 09:38:08
大致情况:电脑、PVR(网络产品)、路由器组成一个小的局域网。路由器动态分配给PVR一个IP,用电脑去ping PVR的IP。

现在是程序运行后单击Button按钮开始ping,button的单击事件如下:


private void button_Click(object sender,EventArgs e)
{
Thread pingTh=null;
if(pingTh!=null)
{
try
{
pingTh.Abort();
}
catch
{

}
finally
{
pingTh=null;
}
}
pingTh=new Thread(Ping); //Ping是具体实现ping PVR的方法。用ICMP数据包实现ping。
PingTh.Start();
}


现在我想修改为程序运行后,插上网线,然后判断PVR是否获取了路由器动态分配的IP,如果已经获取了,程序不用Button按钮触发,直接执行pingTh.Start()。

现在我关键不知道代码应该加在什么地方?Form_Load里面肯定不行。谁能给个思路,谢谢!程序只差这最后一个问题了。
(只剩下这么多的分了)

...全文
162 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lym44466 2010-09-21
  • 打赏
  • 举报
回复
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//要写的代码
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
xzjxylophone 2010-09-21
  • 打赏
  • 举报
回复
启动一个新的线程
在后台每隔2-3秒执行一次
gohappy2008 2010-09-21
  • 打赏
  • 举报
回复

可以通过timer控件的Tick事件进行检测 ,每一秒或两秒就搜索依次。
yinrongg 2010-09-21
  • 打赏
  • 举报
回复
用timer加线程定时去PING。
ksa2736 2010-09-21
  • 打赏
  • 举报
回复
在main里面运行
netstray 2010-09-21
  • 打赏
  • 举报
回复
学习中………………
gaoxing_1985007 2010-09-21
  • 打赏
  • 举报
回复
快要上班去了,看看还有没有别的好的方法。
gaoxing_1985007 2010-09-20
  • 打赏
  • 举报
回复
我试试看,谢谢。
[Quote=引用 4 楼 zhangaijiang 的回复:]
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
static class Program
{
/// <sum……
[/Quote]
zhangaijiang 2010-09-20
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//要写的代码
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}


楼主不妨把代码放到这里,试试看.
gaoxing_1985007 2010-09-20
  • 打赏
  • 举报
回复
一块期待高人指点一下吧
[Quote=引用 2 楼 nofc2006 的回复:]
我也感兴趣
[/Quote]
全栈深入 2010-09-20
  • 打赏
  • 举报
回复
我也感兴趣
gaoxing_1985007 2010-09-20
  • 打赏
  • 举报
回复
帮帮忙,谢谢了。

110,569

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧