// user statuses: // 0 - free // 1 - talking // 2 - in queue public static void StartChanceCalculation(this User user, ControllerService controllerService) { int chance = 30; // in percents int callDelay = 60; // in seconds using (var dbContext = new TelecommunicationNetworkSimulatorContext()) { var rnd = new Random(); while (true) { int chanceGenerated = rnd.Next(100); if ( dbContext.BaseStations .Where(bs => bs.Id == user.BaseStationId) .FirstOrDefault() .BaseStationStatusId == 1 ) { if (chanceGenerated > chance) { Thread.Sleep(callDelay * 1000); } else { User otherUser = dbContext.Users.ToList()[rnd.Next(dbContext.Users.Count())]; while (otherUser == user) { otherUser = dbContext.Users.ToList()[rnd.Next(dbContext.Users.Count())]; } user.Call(otherUser, controllerService); } } } } }