public void Test10ScanWithPauseAndCancel() { using (ScanFS fileScan = new ScanFS()) { fileScan.SetDirectories( new DirectoryInfo[] { new DirectoryInfo(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\trace\src\FS.Tests\TestFiles\TestGetItemCount1")) }); ScanFSEventSink scannerSink = new ScanFSEventSink(fileScan, 1); Thread fred = new Thread(new ParameterizedThreadStart(ScannerWorker)); fred.Name = "Test_10_ScanWithPauseAndCancel_ScannerWorker"; fred.Start(fileScan); while (1 > scannerSink.FilesFound) { Thread.Sleep(1); } fileScan.Pause(); int currentAmountOfFileEventsFired = scannerSink.FilesFound; Thread.Sleep(200); //should not be getting events while paused Assert.AreEqual(currentAmountOfFileEventsFired, scannerSink.FilesFound); fileScan.Cancel(); //now wait for the call to Execute on the other thread to finish fred.Join(20000); //should have terminated without publishing any more events Assert.AreEqual(currentAmountOfFileEventsFired, scannerSink.FilesFound); } }
public void Test08ScanWithPauseAndDispose() { using (ScanFS fileScan = new ScanFS()) { fileScan.SetDirectories( new DirectoryInfo[] { new DirectoryInfo(Workshare.TestUtils.TestFileUtils.MakeRootPathAbsolute(@"\Projects\trace\src\FS.Tests\TestFiles\TestGetItemCount1")) }); ScanFSEventSink scannerSink = new ScanFSEventSink(fileScan,1 ); //Start scanning on a different thread. Thread fred = new Thread(new ParameterizedThreadStart(ScannerWorker)); fred.Name = "Test_8_ScanWithPauseAndDispose_ScannerWorker"; fred.Start(fileScan); //When at least 1 file is detected, pause the process. while (1 > scannerSink.FilesFound) { Thread.Sleep(1); } fileScan.Pause(); int currentAmountOfFileEventsFired = scannerSink.FilesFound; System.Threading.Thread.Sleep(500); Assert.AreEqual(currentAmountOfFileEventsFired, scannerSink.FilesFound); } }