c# - TcpClient ConnectAsync get status -
is there way can status of tcpclient async connection? using following code, how can status of client using connected property? try establish remote connection asynchronously in same time don't wait more 5 seconds ...
tcpclient client = new tcpclient(); task tsk = task.factory.startnew(() => { client.connectasync(host, port); // client.connect (this false) }); tsk.wait(5000); // client.connect (or if use here, false)
first off, not create new task
of own; bug. connectasync
returns task
represents connection attempt:
var tsk = client.connectasync(host, port); tsk.wait(5000);
after wait returns, check iscompleted
property of task; true
if , if connection established.
Comments
Post a Comment