timer tick event e tcpclient.connect, how to ?
To resolve the problem of looong timeout of tcpclient (CF 2, WinMobile 6, VS 2005) connect method, i try this code but don't work. L'event tick don't work after tcpclient.connect method is calling:
public TCPClient TCPClient1 = null;
private void menuItem3_Click(object sender, EventArgs e)
{
IPAddress serverIP = IPAddress.Parse("192.168.0.1");
TCPClient1 = new TcpClient();
timer1.Interval = 5000;
timer1.Enabled = true;
Application.DoEvents();
try
{
TCPClient1.Connect(new IPEndPoint(serverIP, 6001));
}
catch (Exception ex)
{
timer1.Enabled = false;
textBox1.Text += ex.Message+"\r\n";
}
}
private void timer1_Tick(object sender, EventArgs e)
{
//this event should be fired during method connect... but not !
if (TCPClient1.Client.Connected)
{
textBox1.Text += "Connected\r\n";
}
else
{
textBox1.Text += "Not connected and release resource\r\n";
TCPClient1.Close();
TCPClient1 = null;
}
timer1.Enabled = false;
}