/// <summary> /// Check box 1 tells the program to run the program after 6pm and to pause at 7am /// Check box 2 tells the program to do a move. /// There is only one check for check box 2 here, because I then do a check inside /// The method /// </summary> /// <param name="sender"></param> /// <param name="e"></param> internal async void startBtn_Click(object sender, EventArgs e) { isRunning = true; StartDirectory = @SrcPath.Text; EndDirectory = @DestPath.Text; StartDirEnd = Alphaleonis.Win32.Filesystem.Path.GetFileName(StartDirectory.TrimEnd(Alphaleonis.Win32.Filesystem.Path.DirectorySeparatorChar)); logdir = @"\\path\to\logs"; logdir = Alphaleonis.Win32.Filesystem.Path.Combine(logdir, uname); string logname = String.Format("{0}__{1}", DateTime.Now.ToString("yyyyMMdd_hh.mm.ss"), StartDirEnd); string logfile = Alphaleonis.Win32.Filesystem.Path.Combine(logdir, logname); _cts = new CancellationTokenSource(); var token = _cts.Token; _pts = new PauseTokenSource(); var pausetoken = _pts.Token; progressBar1.Value = 0; progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Marquee; timer1.Tick += new EventHandler(Timer1_Tick); timer2.Tick += new EventHandler(Timer2_Tick); timer3.Tick += new EventHandler(Timer3_Tick); ///This will check the time. If after 6pm it will start now ///If before 6 it starts the timer loop (where it starts timer 2 ///and then waits for it hit 7am, before pausing, going to timer 1 to 6). if (checkBox1.Checked) { /// Because of how I am doing the timings, I want a pause function to be set to paused whenever the After 6 /// option is selected. This will prevent it from running until timer1 ends. _pts.IsPaused = !_pts.IsPaused; if (DateTime.Now < SixPM) { this.Invoke((MethodInvoker) delegate { listBox1.Items.Add("This will start after 6pm, and then stop at 7am. It will loop until complete"); listBox1.TopIndex = listBox1.Items.Count - 1; }); PrepareControlForStart(); timer1.Interval = (int)MilliSecondsToNextTargetTime(); timer1.Start(); timer3.Interval = 1000; timer3.Start(); } /// If the user ends up starting after 6, this will just start the job right away and then start /// timer2. Since timer 2 is 7am, unless this starts past midnight, it won't throw any errors. /// TODO: Add code so that after midnight there is no errors. For now there is a very tiny chance this will happen. if (DateTime.Now >= SixPM) { PauseBtn_Click(sender, e); PrepareControlForStart(); this.Invoke((MethodInvoker) delegate { listBox1.Items.Add("**********File Copy has Started!*****"); listBox1.TopIndex = listBox1.Items.Count - 1; }); timer2.Interval = (int)MilliSecondsToNextPauseTime(); timer2.Start(); await RunCopyorMove(StartDirectory, EndDirectory, pausetoken, token, logfile, filesSkipped, filesCopied, isRunning, sum, endsum, progressvalue, progressum); } } ///This is only indication of a move. Everything else is a copy, except for if you do checkbox 1, and then the check is in method if (!checkBox1.Checked && (checkBox2.Checked)) { this.Invoke((MethodInvoker) delegate { listBox1.Items.Add("**********File Move has Started!*****"); listBox1.TopIndex = listBox1.Items.Count - 1; listBox1.Items.Add("This will delete the source path. If you did not intend that please hit Stop Copy"); listBox1.TopIndex = listBox1.Items.Count - 1; }); PrepareControlForStart(); await RunCopyorMove(StartDirectory, EndDirectory, pausetoken, token, logfile, filesSkipped, filesCopied, isRunning, sum, endsum, progressvalue, progressum); } /// If no option selected it runs now, and does a copy if (!checkBox1.Checked && (!checkBox2.Checked)) { this.Invoke((MethodInvoker) delegate { listBox1.Items.Add("**********File Copy has Started!*****"); listBox1.TopIndex = listBox1.Items.Count - 1; }); PrepareControlForStart(); await RunCopyorMove(StartDirectory, EndDirectory, pausetoken, token, logfile, filesSkipped, filesCopied, isRunning, sum, endsum, progressvalue, progressum); } }
internal PauseToken(PauseTokenSource source) { m_source = source; }