110,545
社区成员
发帖
与我相关
我的任务
分享
public void hexing_name_select()
{
hexing_line hexing = new hexing_line();
for (int i = 0; i < hexing.hexing_name.Count(); i++)
{
hexing_date.Rows.Add();
hexing_date.Rows[i].Cells[0].Value = hexing.hexing_name[i];
hexing_date.Rows[i].Cells[1].Value = hexing.hexing_ip[i];
}
}
public void hexing_ping(object obj)
{
int i = Convert.ToInt32(obj);
Ping pp = new Ping();
PingReply ppResult = pp.Send(Convert.ToString(hexing_date.Rows[i].Cells[1].Value), 10);
hexing_date.Rows[i].Cells[2].Value = ppResult.RoundtripTime.ToString();
hexing_date.Rows[i].Cells[3].Value = ppResult.Status.ToString();
hexing_date.Rows[i].Cells[4].Value = z;
}
static System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
public void hexing_click_select(object source, EventArgs e)
{
//myTimer.Stop();我尝试了下,这个stop不stop都不会影响到ping的时候会卡界面的情况。
z+=1;
if (z < 10)
{
hexing_thread();
myTimer.Enabled = true;////是不是这一句起到了作用?求解
}
else
{
myTimer.Enabled = false;
}
}
public void hexing_thread()
{
int line_count = hexing_date.RowCount;
Thread[] line_PING = new Thread[line_count];
for (int a = 0; a < line_count; a++)
{
line_PING[a] = new Thread(new ParameterizedThreadStart(hexing_ping));
line_PING[a].Start(a);
}
}
private void hexing_check_Click(object sender, EventArgs e)
{
hexing_date.Rows.Clear();
hexing_name_select();
myTimer.Tick += new EventHandler(hexing_click_select);
myTimer.Interval = 1000;
myTimer.Start();
}
System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
private void hexing_check_Click(object sender, EventArgs e)
{
hexing_date.Rows.Clear();
hexing_name_select();
z = 0;
hexing_check.Enabled = false;
myTimer.Tick += new EventHandler(hexing_click_select);
myTimer.Interval = 1000;
myTimer.Start();
}
private void hexing_stop_Click(object sender, EventArgs e)
{
z = 0;
myTimer.Stop();
hexing_check.Enabled = true;
}
public void hexing_click_select(object source, EventArgs e)
{
myTimer.Stop();
z += 1;
if (z < 10)
{
hexing_thread();
}
else
{
int click_all = z - 1;
z = 0;
click_all = 0;
myTimer.Enabled = false;
}
}
public void hexing_thread()
{
int line_count = hexing_date.RowCount;
Thread[] line_PING = new Thread[line_count];
for (int a = 0; a < line_count; a++)
{
line_PING[a] = new Thread(new ParameterizedThreadStart(hexing_ping));
line_PING[a].Start(a);
}
myTimer.Start();
}
public void hexing_ping(object obj)
{
int i = Convert.ToInt32(obj);
Ping pp = new Ping();
PingReply ppResult = pp.Send(Convert.ToString(hexing_date.Rows[i].Cells[1].Value), 10);
hexing_date.Rows[i].Cells[2].Value = ppResult.RoundtripTime.ToString();
hexing_date.Rows[i].Cells[3].Value = ppResult.Status.ToString();
hexing_date.Rows[i].Cells[4].Value = z;
}
大神,你看看我现在改的对么,,我把 myTimer.Start()放在hexing_thread(),,,我这边测试了下,一切正常,,,但是我有个疑问就是我点击 暂停 按钮后,然后重新点击开始,那个z会变成从2开始每次递增2,然后再暂停开始,又变成从3开始数,每次递增3,为啥z不会变为0(z这里是用来统计我ping了多少次IP,) public void hexing_ping(object obj)
{
int i = Convert.ToInt32(obj);
Ping pp = new Ping();
PingReply ppResult = pp.Send(Convert.ToString(hexing_date.Rows[i].Cells[1].Value), 10);
hexing_date.Rows[i].Cells[2].Value = ppResult.RoundtripTime.ToString();
hexing_date.Rows[i].Cells[3].Value = ppResult.Status.ToString();
hexing_date.Rows[i].Cells[4].Value = z;
// myTimer.Enabled = true;
myTimer.Start();
}
public void hexing_click_select(object source, EventArgs e)
{
myTimer.Stop();
//myTimer.Enabled = false;
z+=1;
if (z < 10)
{
hexing_thread();
myTimer.Enabled = true;
}
else
{
int click_all = z - 1;
z = 0;
click_all = 0;
myTimer.Enabled = false;
}
}
我按照你的方法,我试了下,,就是不管我用start还是enable=true都无法再暂停后启动。。。
现在我就是卡在这里,,,想又想不懂,,然后百度上查了下,,又没有具体的解决方案,