public virtual SpawnTask Spawn(RoomOptions options)
        {
            var spawners = GetFilteredSpawners(options.Region);

            if (spawners.Count < 0)
            {
                WriteEvent("No spawner was returned after filtering. " +
                           (string.IsNullOrEmpty(options.Region) ? "" : "Region: " + options.Region), LogType.Warning);
                return(null);
            }

            // Order from least busy server
            var orderedSpawners  = spawners.OrderByDescending(s => s.CalculateFreeSlotsCount());
            var availableSpawner = orderedSpawners.FirstOrDefault(s => s.CanSpawnAnotherProcess());

            // Ignore, if all of the spawners are busy
            if (availableSpawner == null)
            {
                return(null);
            }

            var task = new SpawnTask(GenerateSpawnTaskId(), availableSpawner, options);

            _spawnTasks.Add(task);

            availableSpawner.AddTaskToQueue(task);

            Dispatcher.InvokeWait(() => WriteEvent("Spawner was found, and spawn task created: " + task, LogType.Trace));

            return(task);
        }
 public void AddTaskToQueue(SpawnTask task)
 {
     _queue.Enqueue(task);
 }