private void StopService() { if (ServiceFiber != null) { ServiceFiber.Stop(); ServiceFiber.Dispose(); ServiceFiber = new PoolFiber(); } }
public void ExecuteOnlyAfterStart() { PoolFiber fiber = new PoolFiber(); AutoResetEvent reset = new AutoResetEvent(false); fiber.Enqueue(delegate { reset.Set(); }); Assert.IsFalse(reset.WaitOne(1, false)); fiber.Start(); Assert.IsTrue(reset.WaitOne(1000, false)); fiber.Stop(); }
public void Should_prevent_new_actions_from_being_queued() { Fiber fiber = new PoolFiber(); var called = new Future<bool>(); fiber.Stop(); fiber.Add(() => called.Complete(true)); fiber.Shutdown(10.Seconds()); called.IsCompleted.ShouldBeFalse(); }
public void Should_prevent_new_actions_from_being_queued() { Fiber fiber = new PoolFiber(); var called = new Future <bool>(); fiber.Stop(); fiber.Add(() => called.Complete(true)); fiber.Shutdown(10.Seconds()); called.IsCompleted.ShouldBeFalse(); }
/// <summary> /// Stops this instance. /// </summary> public void Stop() { lock (syncRoot) { Interlocked.Exchange(ref state, 0L); fiber.Stop(); if (timerControl != null) { timerControl.Dispose(); timerControl = null; } sampleDictionary.Clear(); } }
public void Should_not_stall_the_scheduler() { Fiber stopped = new PoolFiber(); stopped.Stop(); Fiber running = new PoolFiber(); Scheduler scheduler = new TimerScheduler(new PoolFiber()); var called = new Future <bool>(); scheduler.Schedule(200.Milliseconds(), stopped, () => { }); scheduler.Schedule(400.Milliseconds(), running, () => called.Complete(true)); called.WaitUntilCompleted(2.Seconds()).ShouldBeTrue(); }
public void Should_not_stall_the_scheduler() { Fiber stopped = new PoolFiber(); stopped.Stop(); Fiber running = new PoolFiber(); Scheduler scheduler = new TimerScheduler(new PoolFiber()); var called = new Future<bool>(); scheduler.Schedule(200.Milliseconds(), stopped, () => { }); scheduler.Schedule(400.Milliseconds(), running, () => called.Complete(true)); called.WaitUntilCompleted(2.Seconds()).ShouldBeTrue(); }
/// <summary> /// The main entry point for the application. /// </summary> /// <param name="args"> /// The args. /// </param> private static void Main(params string[] args) { LogManager.SetLoggerFactory(ExitGames.Logging.Log4Net.Log4NetLoggerFactory.Instance); Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory); // Set logfile name and application name variables FileInfo configFileInfo; try { // IOException if another process already writes to the file if (File.Exists(@"log\" + firstGameName + ".log")) { File.Delete(@"log\" + firstGameName + ".log"); } GlobalContext.Properties["LogName"] = firstGameName + ".log"; configFileInfo = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4net.config")); } catch (IOException) { GlobalContext.Properties["LogName"] = baseGameName + ".log"; // just write to console for now configFileInfo = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log4netConsole.config")); } XmlConfigurator.ConfigureAndWatch(configFileInfo); AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; WindowsCounters.Initialize(); int index = 0; if (args.Length > index) { Settings.TestCase = args[index]; } index++; if (args.Length > index) { Settings.NumGames = byte.Parse(args[index]); } index++; if (args.Length > index) { Settings.NumClientsPerGame = byte.Parse(args[index]); } index++; if (args.Length > index) { Settings.ServerAddress = args[index]; } index++; if (args.Length > index) { Settings.FlushInterval = int.Parse(args[index]); } index++; if (args.Length > index) { Settings.SendReliableData = bool.Parse(args[index]); } index++; if (args.Length > index) { Settings.ReliableDataSendInterval = int.Parse(args[index]); } index++; if (args.Length > index) { Settings.SendUnreliableData = bool.Parse(args[index]); } index++; if (args.Length > index) { Settings.UnreliableDataSendInterval = int.Parse(args[index]); } Console.WriteLine("Test case: " + Settings.TestCase); Console.WriteLine("Settings: {0} games per process, {1} players per game, game server at {2}", Settings.NumGames, Settings.NumClientsPerGame, Settings.ServerAddress); if (Settings.SendReliableData) { Console.WriteLine("Sending reliable operation every {0} ms", Settings.ReliableDataSendInterval); } if (Settings.SendUnreliableData) { Console.WriteLine("Sending unreliable operation every {0} ms", Settings.UnreliableDataSendInterval); } Console.WriteLine(); stopped = false; fiber.Start(); counterLoggingFiber.Start(); counterLoggingFiber.ScheduleOnInterval(PrintCounter, Settings.LogCounterInterval, Settings.LogCounterInterval); try { log.InfoFormat("Starting {0} games with {1} players", Settings.NumGames, Settings.NumClientsPerGame); for (int g = 0; g < Settings.NumGames; g++) { fiber.Enqueue(StartGame); } ////log.InfoFormat("{0} clients running", clients.Count); Console.WriteLine("[{0}] Press Return to End", Process.GetCurrentProcess().Id); Console.ReadLine(); ////log.InfoFormat("Stopping {0} clients", clients.Count); StopGames(); fiber.Stop(); // wait for stop to complete resetEvent.WaitOne(); } catch (Exception e) { log.Error(e); } finally { log.InfoFormat("[{0}] Stopped", Process.GetCurrentProcess().Id); } }