Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Timer to move file from one dir to another dir

$
0
0

I want to transfer one file for every seconds from one dir to another dir.

I have a timer but it's not working.

During button click is transferring one file & another click it's transferring another file. 

How can i transfer one file for every 3 seconds by using the timer?

Code:

private System.Timers.Timer MyTimer; private void bStart_Click(object sender, RoutedEventArgs e) { string targetPath = @"C:\Test\HFP\Prints\3_5x5\"; if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } DirectoryInfo dirInfo = new DirectoryInfo(targetPath); if (dirInfo.Exists == false) Directory.CreateDirectory(targetPath); List<String> myImages = Directory .GetFiles(destination_dir35x5, "*.*", SearchOption.TopDirectoryOnly).ToList(); int i = 0; MyTimer = new System.Timers.Timer(); MyTimer.Interval = 3000; MyTimer.Start(); MyTimer.Enabled = true; string file = myImages[i]; FileInfo mFile = new FileInfo(file); if (new FileInfo(dirInfo + "\\" + mFile.Name).Exists == false) mFile.MoveTo(dirInfo + "\\" + mFile.Name); i++; b35x5Stop.IsEnabled = true; b35x5Send.IsEnabled = false; }

//Button to stop the timer private void b35x5Stop_Click(object sender, RoutedEventArgs e) { MyTimer.Stop(); b35x5Send.IsEnabled = true; }



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>