File Transfer is designed to run Windows Services in the background. In the configuration file, you need to define a timer to check whether the specified time has arrived, in this way. net has several class libraries with timer definitions. For details, refer to msdn.
I used space system. timer In timers can set a time interval to execute events defined by elapsedeventhandler at intervals. Due to unstable network conditions, disconnection may occur from time to time, therefore, we need to define a time period. During this time period, we will check whether there are files to be uploaded at a certain time. However, due to the uncertainty of network transmission, the interval between checks is a problem, because the system. timer is multi-threaded, So if not processed, it will lead to resource competition. For example, the interval of timer is defined as 360000, that is, check whether a file needs to be uploaded or downloaded every six minutes. If the elapsedeventhandler event triggered by the previous timer is not completed, and the elapsedeventhandler event is triggered again, a problem occurs, you need to apply a lock through system. implement interlocked in threading.
Execute event processing when the value of the locavar variable is 0.ProgramCorrespondingCodeWhen the code is executed
If ( 0 = Interlocked. Exchange ( Ref Lockvar, 1 ))
Reset the value of lockvar after execution.
// Release lock
Interlocked. Exchange ( Ref Lockvar, 0 );