private static void Main(string[] args) { try { AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; Console.WriteLine("Press <Enter> to start emulation..."); Console.ReadLine(); int threads; int iothreads; ThreadPool.GetMinThreads(out threads, out iothreads); DedicatedThreadPool threadPool = new DedicatedThreadPool(new DedicatedThreadPoolSettings(threads)); ThreadPool.SetMinThreads(32000, 4000); ThreadPool.SetMaxThreads(32000, 4000); Emulator emulator = new Emulator {Running = true}; Stopwatch watch = new Stopwatch(); watch.Start(); long start = DateTime.UtcNow.Ticks; //IPEndPoint endPoint = new IPEndPoint(Dns.GetHostEntry("yodamine.com").AddressList[0], 19132); IPEndPoint endPoint = new IPEndPoint(IPAddress.Loopback, 19132); for (int j = 0; j < NumberOfBots; j++) { string playerName = $"TheGrey{j + 1:D3}"; ClientEmulator client = new ClientEmulator(threadPool, emulator, DurationOfConnection, playerName, (int) (DateTime.UtcNow.Ticks - start), endPoint, RanSleepMin, RanSleepMax, RequestChunkRadius); new Thread(o => { client.EmulateClient(); }) {IsBackground = true}.Start(); //ThreadPool.QueueUserWorkItem(delegate { client.EmulateClient(); }); Thread.Sleep(TimeBetweenSpawns); } Console.WriteLine("Press <enter> to stop all clients."); Console.ReadLine(); emulator.Running = false; } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("Emulation complete. Press <enter> to exit."); Console.ReadLine(); }
public ClientEmulator(DedicatedThreadPool threadPool, Emulator emulator, TimeSpan timeToRun, string name, int clientId, IPEndPoint endPoint, int ranMin = 150, int ranMax = 450, int chunkRadius = 8) { _threadPool = threadPool; Emulator = emulator; TimeToRun = timeToRun; Name = name; ClientId = clientId; EndPoint = endPoint; RanMin = ranMin; RanMax = ranMax; ChunkRadius = chunkRadius; }
public PoolWorker(DedicatedThreadPool pool, int workerId) { _pool = pool; _threadExit = new TaskCompletionSource <object>(); var thread = new Thread(RunThread, pool.Settings.ThreadMaxStackSize); thread.IsBackground = pool.Settings.ThreadType == ThreadType.Background; if (pool.Settings.Name != null) { thread.Name = string.Format("{0}_{1}", pool.Settings.Name, workerId); } if (pool.Settings.ApartmentState != ApartmentState.Unknown) { thread.SetApartmentState(pool.Settings.ApartmentState); } thread.Start(); }
public PoolWorker(DedicatedThreadPool pool, int workerId) { _pool = pool; _threadExit = new TaskCompletionSource<object>(); var thread = new Thread(RunThread, pool.Settings.ThreadMaxStackSize); thread.IsBackground = pool.Settings.ThreadType == ThreadType.Background; if (pool.Settings.Name != null) thread.Name = string.Format("{0}_{1}", pool.Settings.Name, workerId); if (pool.Settings.ApartmentState != ApartmentState.Unknown) thread.SetApartmentState(pool.Settings.ApartmentState); thread.Start(); }
public DedicatedThreadPoolTaskScheduler(DedicatedThreadPool pool) { _pool = pool; }
public DedicatedThreadPoolTaskScheduler(DedicatedThreadPool pool) { _pool = pool; }