/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="destination"></param> public void CopyFileAsynch(string source, string destination) { if (CheckThreadIsAlreadyRunning()) { return; } this.sourceFile = source; this.destinationFile = destination; finishedEventArgs.destinationDir = destination; finishedEventArgs.sourceDir = source; // Check if Data is valid if (File.Exists(this.sourceFile)) { // Start the Copying thread copyFileThread = new Thread(CopyFileThread); copyFileThread.Start(); } else { finishedEventArgs.allFilesCopyedAndNoError = false; finishedEventArgs.notCopyedFiles = new List<string>(); finishedEventArgs.notCopyedFiles.Add("Source Directory not found. No wile was copyed"); finishedEventArgs.timeElapsed = 0; // Hit the event that we have finished without copying anything CopyFinished.Invoke(this, finishedEventArgs); } }
/// <summary> /// Copy function. Attention! /// </summary> private void CopyDirectoryThread() { // Reset the stop bit stopCopyDirectoryThread = false; // Get the overal amount of data //DirectoryInfo dir = new DirectoryInfo(sourceDir); // Start the elapsed time measurements Stopwatch _stopwatch = new Stopwatch(); _stopwatch.Start(); // get the size of the source directory //GetDirectoryMegaByteSize(this.sourceDir, true); // Perform the Copy finishedEventArgs.allFilesCopyedAndNoError = true; copyDirectory(this.sourceDir, this.destinationDir, true); // get the size of the destination directory //GetDirectoryMegaByteSize(this.destinationDir, true); // After we are done send teh finished Event _stopwatch.Stop(); finishedEventArgs.timeElapsed = _stopwatch.ElapsedMilliseconds; if (stopCopyDirectoryThread) { finishedEventArgs.allFilesCopyedAndNoError = false; } // Hit the event that we have finished without copying anything CopyFinished.Invoke(this, finishedEventArgs); }
void AbortTimerTick(Object sender , EventArgs e) { if (m_CopyThread.IsAlive == false) { AbortTimer.Stop(); m_CopyThread = null; UpdateProgressBar(-1, DateTime.Now); CopyFinished?.Invoke(this, EventArgs.Empty); } }
/// <summary> /// /// </summary> private void CopyFileThread() { // Start measuring the leapsed time Stopwatch _stopwatch = new Stopwatch(); _stopwatch.Start(); finishedEventArgs.allFilesCopyedAndNoError = true; // Preset the Args with true. Will be set to false if an error occured copyFile(this.sourceFile, this.destinationFile, true); // Safe the elapsed Time to the event argument _stopwatch.Stop(); finishedEventArgs.timeElapsed = _stopwatch.ElapsedMilliseconds; CopyFinished.Invoke(this, finishedEventArgs); // Hit the event that we have finished without copying anything }
private void GetFiles() { _filesToCopy = new List <FlashAirFileInformation>(); int imageCount = LoadFlashairInfo(_connection.Settings.CardStartupPath); if (imageCount < 0) { _log.Warn("Cannot retrieve files"); return; } TotalFiles = imageCount; FilesCopied = 0; foreach (var singleFile in _filesToCopy) { DoCopy(singleFile); } if (CopyFinished != null) { CopyFinished.Invoke(this, new EventArgs()); } }
/// <summary> /// /// </summary> /// <param name="sourceDirectory"></param> /// <param name="destinationDirectory"></param> public bool CopyDirectoryAsynch(string sourceDirectory, string destinationDirectory) { finishedEventArgs.destinationDir = destinationDirectory; finishedEventArgs.sourceDir = sourceDirectory; bool _retVal = false; if (CheckThreadIsAlreadyRunning()) { return _retVal; } // Set the directorys this.destinationDir = destinationDirectory; this.sourceDir = sourceDirectory; // Check if Data is valid if (Directory.Exists(sourceDir)) { // Start the Copying thread copyDirectoryThread = new Thread(CopyDirectoryThread); copyDirectoryThread.Start(); _retVal = true; } else { finishedEventArgs.allFilesCopyedAndNoError = false; finishedEventArgs.notCopyedFiles = new List<string>(); finishedEventArgs.notCopyedFiles.Add("Source Directory not found. No wile was copyed"); finishedEventArgs.timeElapsed = 0; // Hit the event that we have finished without copying anything CopyFinished.Invoke(this, finishedEventArgs); } return _retVal; }