How to use Ping.SendAsync working with datagridview?

前端 未结 2 2047
囚心锁ツ
囚心锁ツ 2021-01-28 02:18

I have an application that pings every IP in the datagridview in order to compile a list of responsive IP RoundtripTime.When finished the step,I will push the RoundtripTime back

2条回答
  •  一个人的身影
    2021-01-28 02:56

    What KAJ said. But there is a chance of mixing up results of ping requests because they are not connected to ip addresses in grid. One could not tell which host will respond first, and if there is a ping > 5ms anything can happen because currentrow is changing in between callbacks. What you need to do is to send a datagridviewrow reference to a callback. To do that, use an overload of SendAsync:

    ping.SendAsync(ip, 1000, row);
    

    And in a callback:

    DataGridViewRow row = e.UserState as DataGridViewRow;
    

    You might also want to check reply.Status to make sure that request did not time-out.

提交回复
热议问题