private static void TickStop(System.Timers.Timer timer, CallObj data) { timer.Stop(); data.EndTime = DateTime.Now; activeCalls--; numbersInUsage.Remove(data.PhoneNumber); object[] obj = new object[] { data.PhoneNumber, data.ContactNumber, data.StartTime, data.EndTime }; calls.Add(obj); }
private static void Tick(System.Timers.Timer timer, CallObj data, int aveTime) { timer.Stop(); data.StartTime = DateTime.Now; activeCalls++; try { numbersInUsage.Add(data.PhoneNumber); } catch { } timer = new System.Timers.Timer(); int phoneCallTime = rand.Next((aveTime * 60 / 100), (aveTime * 120 / 100)); if (phoneCallTime < 0) { phoneCallTime = 100; } timer.Interval = phoneCallTime; timer.Elapsed += new System.Timers.ElapsedEventHandler((s, e) => TickStop(timer, data)); timer.Start(); }
private static void NewCall(int number, int contactNumber, int averageCallTime) { CallObj data = new CallObj() { ContactNumber = contactNumber, PhoneNumber = number, }; if (averageCallTime == 0) { averageCallTime = rand.Next(60000, 1800000); } System.Timers.Timer timer = new System.Timers.Timer(); int sleep = rand.Next(1, 60000 - 2); timer.Interval = sleep; timer.Elapsed += new System.Timers.ElapsedEventHandler((s, e) => Tick(timer, data, averageCallTime)); timer.Start(); }