private VideoItemFileInfo RunFileWaitForExit(VideoItemFileInfo videoItemFileInfo, DoWorkEventArgs doWorkEvent) { VideoItemFileInfo resultsVideoItemFileInfo = new VideoItemFileInfo(); // Abort the operation if the user has canceled. // Note that a call to CancelAsync may have set // CancellationPending to true just after the // last invocation of this method exits, so this // code will not have the opportunity to set the // DoWorkEventArgs.Cancel flag to true. This means // that RunWorkerCompletedEventArgs.Cancelled will // not be set to true in your RunWorkerCompleted // event handler. This is a race condition. if (backgroundWorker.CancellationPending) { doWorkEvent.Cancel = true; resultsVideoItemFileInfo.elapsed = 0; resultsVideoItemFileInfo.videoInfo = null; resultsVideoItemFileInfo.videoItemFile = null; return(resultsVideoItemFileInfo); } Stopwatch stopwatch = Stopwatch.StartNew(); percentComplete = 0; string playing = videoItemFileInfo.videoItemFile.Name; if (playing.Length > 30) { playing = playing.Substring(0, 30) + ".. "; } backgroundWorker.ReportProgress(percentComplete, "Playing\n" + playing + ".."); FileInfo fileInfo = videoItemFileInfo.GetFileInfo(); bool ret = MyFile.RunFile(fileInfo); percentComplete = 100; backgroundWorker.ReportProgress(percentComplete, "Finished playing\n" + playing); stopwatch.Stop(); resultsVideoItemFileInfo.elapsed = (long)Math.Floor((decimal)stopwatch.ElapsedMilliseconds / 1000); resultsVideoItemFileInfo.videoInfo = videoItemFileInfo.videoInfo; resultsVideoItemFileInfo.videoItemFile = videoItemFileInfo.videoItemFile; // meh, so completed msg shows Thread.Sleep(500); return(resultsVideoItemFileInfo); }
private void toolStripMenuItemOpen_Click(object sender, EventArgs e) { // item unselected, so ignore if (listView.SelectedItems.Count == 0) { return; } VideoItemFileInfo videoItemFileInfo = (VideoItemFileInfo)listView.SelectedItems[0].Tag; if (videoItemFileInfo == null) { return; } FileInfo fileInfo = videoItemFileInfo.GetFileInfo(); if (fileInfo == null) { return; } MyFile.RunFile(fileInfo); }