コード例 #1
0
 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);
 }
コード例 #2
0
        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();
        }
コード例 #3
0
        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();
        }