public void CanBeUsedWithTheUsingCSharpIdiomToAttemptOnAnISync() { // no expectations mocks.ReplayAll(); MySemaphore sync = new MySemaphore(1); using (new SyncHolder(sync, 100)) { Assert.AreEqual(0, sync.Permits); } Assert.AreEqual(1, sync.Permits); sync = new MySemaphore(0); try { using (new SyncHolder(sync, 100)) { Assert.IsTrue(false, "wrongly entered sync block"); } } catch (TimeoutException) { Assert.AreEqual(0, sync.Permits); } }
/// <summary> /// resets current state of the program /// </summary> private void RestartButton_Click(object sender, RoutedEventArgs e) { FinishButton.Visibility = Visibility.Hidden; ConclusionTextBox.Visibility = Visibility.Visible; ConclusionInfo.Visibility = Visibility.Visible; mySemaphore = new MySemaphore(0, 1); ConcreteObservations.Clear(); Rules.Clear(); Observations.Clear(); /* * string[] testExamples = * { * "AKO e1 ONDA (0.3)z1", * "AKO z1 ILI - z2 ONDA (0.6)z", * "AKO e2 ONDA (0.6)z2", * "AKO e3 ONDA (0.7)z1", * "AKO e4 ONDA (0.5)z1" * }; * * foreach (var testExample in testExamples) * { * Rule rule = PostfixConverter.RuleConversion(testExample); * AddRule(rule); * } */ RichTextBox.Document.Blocks.Clear(); }
private void ToggleButton_Switcher_Click(object sender, RoutedEventArgs e) { if (!(sender is ToggleButton)) { return; } if ((sender as ToggleButton).IsChecked == true) { MySemaphore.WaitOne(); this.DirectXPanel.Clear((int)ParticleType.Rain); MySemaphore.Release(); this.PointerMoved -= Page_PointerMoved; this.timer.Change(0, timerSpeed / 20); this.particleType = ParticleType.Rain; } else { MySemaphore.WaitOne(); this.DirectXPanel.Clear((int)ParticleType.Snow); MySemaphore.Release(); this.PointerMoved += Page_PointerMoved; this.timer.Change(0, timerSpeed); this.particleType = ParticleType.Snow; } }
private void Page_PointerMoved(object sender, PointerRoutedEventArgs e) { PointerPoint point = e.GetCurrentPoint(this); try { MySemaphore.WaitOne(); this.DirectXPanel.TrackPos((int)Math.Round(point.Position.X), (int)Math.Round(point.Position.Y)); MySemaphore.Release(); } catch { } }
/// <summary> /// starts a worker thread for estimating the entered /// conclusion probability of happening /// </summary> private void ConclusionTextBox_EnterClicked(object sender, KeyEventArgs e) { if (e.Key == Key.Return) { ConcreteObservation conclusion = GetCachedObservationByName(ConclusionTextBox.Text); FinishButton.Visibility = Visibility.Visible; mySemaphore = new MySemaphore(0, 1); Worker myWorker = new Worker(conclusion); Thread myThread = new Thread(myWorker.StartCalculation); myThread.Start(); StepButton.Visibility = Visibility.Visible; ConclusionTextBox.Visibility = Visibility.Hidden; ConclusionInfo.Visibility = Visibility.Hidden; ConclusionTextBox.Clear(); e.Handled = true; } }
private void timerCallback(object state) { MySemaphore.WaitOne(); try { if (this.particleType == ParticleType.Snow) { this.DirectXPanel.CreateParticles(countOfParticles, -1); } else { this.DirectXPanel.CreateParticles(countOfParticles, this.widthOfWindow); } this.DirectXPanel.Move(); this.DirectXPanel.TrackPos(-1, -1); } catch (Exception) { } MySemaphore.Release(); }
public override void NullNumberOfthread() { ISemaphore mySemaphore = new MySemaphore(0); }
public override void NegativeNumberOfthread() { ISemaphore mySemaphore = new MySemaphore(-1); }