|
In our .net CF application we connect every 5 minutes to a FTP-server. The connection is made by 3G/GPRS, sometimes it happens that due to heavy network use the 3g network does not connect to the server. Is there some method to implement a timeout into the connect method. At the moment I created the following solution, but i'm not sure if this is the right approach.
|
|
The code won't work very well because the However, there is actually a built-in timeout support for all
To handle connection error, put a |
|
I have altered the code to ConnError = false; client.Timeout = 10 * 1000; try { client.Connect(OConfig.GetSettingDefault("FTP/Host", "ftp.techcontrol.nl")); } catch (FtpException ex) { AppVars.CurrentCommState = "!Con"; ConnError = true; MessageBox.Show(ex.Message); } if (!ConnError) { try { client.Login("user","password") } finally { } } as the FTP-server address I have entered an invalid/unreachable server. But no exception is being thrown. Can it be that this has to do with the fact I'm using this code in a BackgroundWorker? (OpenNetCF.ComponentModel.BackgroundWorker) We are not familiar with OpenNetCF's BackgroundWorker, but I would expect the message should be displayed. To see what is actually going on during the Connect method and whether it really times out, try using Ftp object's LogWriter property to create a log, as described at http://www.rebex.net/kb/logging.aspx (make sure to change the log path to a -based path that is valid in the CF device) and post the log here or mail it to support@rebex.net - we should then be able to tell what is going on!
(18 Jul '11, 17:33)
Lukas Pokorny ♦♦
|
|
Thanks to the logWriter option I have found out that there was a successful connect, the problem was an incorrect errorhandling at the login method. Also an invalid FTP-server address was used, therefor is was possible to connect to this server. I have tested it with are unreachable IP(not dns name), now there is a proper time-out notification when the server is not responding. Thanks for this good support! |