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;
}
Loading

BangaruBabu PuretiRank #2,987 · 483 reputationPosted Mar 22, 2010, 1:19 AM EDT
In your code Chunk Please CheckOut U Need To Enable Timer Before Tick Event.Try Once
I Think It will Work
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = true;
//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;
}
Regards
BangaruBabu Pureti
dan15 reputationPosted Mar 22, 2010, 6:18 AM EDT
timer1.Interval = 5000;
timer1.Enabled = true;
Application.DoEvents();
try
{
TCPClient1.Connect(new IPEndPoint(serverIP, 6001));
Timer1_tick's event does not occur at fixed time, but the code is blocked on the connect method, while the timer1_tick should serve just to stop after x seconds (in this case 5 seconds).
dan15 reputationPosted Mar 22, 2010, 6:19 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Mar 22, 2010, 5:56 PM EDT
dan15 reputationPosted Mar 24, 2010, 1:30 AM EDT