gankh

hi evryone, I got a new Winform Net 2.0 project. I need to ftp(upload when a specified amount of files coming and download every 15 minutes) the files and it need to be automated. What is the best design Currently my desgn is:

1) Form load event, start the FIleSytemWatcher ( or Main() in Program.cs is better )

2) also at Form load event, start the timer immediately for download files (which timer is best System.Timers System.Threading.Timer)

3) start 2 threads, i increase the counter for total files coming, another reserved for ftp the files . These 2 must be place on the OnChanged event, I think.

4) lock the ftp progress when it's ftp-ing, because double amount of the files coming maybe trigger it again

is it ok Or anyone have better idea




Re: Windows Forms General automate ftp with timer

Peter Ritchie

I would suggest using Form.Timer if the event handlers for FileSystemWatcher events are on your form. FileSystemWatcher will marshal those event handler calls back to the thread that created the form; if you use a timer other than Form.Timer your elapsed events will occur on a different thread and you'll have to deal with cross-thread issues (i.e. synchronization).

I don't see where these 2 threads come in to play, you've got your Elapsed event handler and your FileSystemWtcher event handlers, what do these two other threads do that can't be done in one of these event handlers

Keep in mind, with the above architecture everything is being executed on the Form's thread; if you do something blocking, that will affect the responsiveness of your UI. So, when implementing the FTP part be sure to use asynchronous methods (like BeginGetResponse).






Re: Windows Forms General automate ftp with timer

gankh

Peter Ritchie wrote:

I don't see where these 2 threads come in to play, you've got your Elapsed event handler and your FileSystemWtcher event handlers, what do these two other threads do that can't be done in one of these event handlers

if not 2 threads used, what if let said the desired amount of files come in, trigger the ftp . While the files are ftp-ing, there's another 1 files coming in Will it miss the accuracy of the counter

Peter Ritchie wrote:
Keep in mind, with the above architecture everything is being executed on the Form's thread; if you do something blocking, that will affect the responsiveness of your UI. So, when implementing the FTP part be sure to use asynchronous methods (like BeginGetResponse).

Can BackgroundWorker helps