Por que o IAsyncResult informa todas as portas como abertas?
Eu tenho esse método em execução em um segmento, mas quando eu testá-lo, relatar todas as portas como abertas. parece que o método:var result = client.BeginConnect(host, port, null, null);
não funciona bem ao passar os resultados emvar success = result.AsyncWaitHandle.WaitOne(tcpTimeout);
...
Alguma idéia de como resolver isso?
eu tenteiclient.ConnectAsync(host,port).Wait(TcpTimeout);
mas isso não está funcionando como esperado também ....
public void start()
{
Thread thread1 = new Thread(new ThreadStart(RunScanTcp));
thread1.IsBackground = true;
thread1.Name = "THREAD ME EMER : " + i;
thread1.Priority = System.Threading.ThreadPriority.Highest;
thread1.Start();
}
public void RunScanTcp()
{
while (((port = portList.NextPort()) != -1) && (nderprit != true))
{
TcpClient client = new TcpClient();
count = port;
tcp_count = tcp_count + 1;
Thread.Sleep(10);
try
{
var mre = new ManualResetEvent(false);
Console.WriteLine("Current port count : " + port);
var result = client.BeginConnect(host, port, null, null);
var success = result.AsyncWaitHandle.WaitOne(tcpTimeout);
if (success)
{
Console.WriteLine("PORT IS OPEN : " + port);
received_tcp = received_tcp + 1;
Activity.RunOnUiThread(() =>
{
mre.Set();
});
mre.WaitOne();
client.Close();
}
else
{
client.Close();
}
}
catch (Exception)
{
client.Close();
}
}
}