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
danPosted Mar 24, 2010, 5:30 AM
Sam HobbsPosted Mar 22, 2010, 9:56 PM
danPosted Mar 22, 2010, 10:19 AM
danPosted Mar 22, 2010, 10:18 AM
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).
BangaruBabu PuretiPosted Mar 22, 2010, 5:19 AM
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