public void TimeToDo(object sender, ClassrooomEventArgs e) { List<Classroom> list = e.Rooms; int num = e.Num; ManualResetEvent eventX = new ManualResetEvent(false); int Count = list.Count; ThreadPool.SetMaxThreads(Count, Count); foreach (Classroom classroom in list) { string command = ""; //cid、Pclassindex,Ptime //查询当前时间所在教室的电器设备状态 int isWork = 0; if (DateTime.Now < Config.Config.Courses[num - 1, 0]) { command = repository.FindCommandByCidAndPtimeAndClassIndex(classroom, DateTime.Now, e.Num); isWork = 1; } else if (DateTime.Now > Config.Config.Courses[num - 1, 1]) { command = repository.FindCloseCommand(classroom); } Thr t = new Thr(classroom, num, isWork, sender); ThreadPool.QueueUserWorkItem(t.ThreadProc, command); // int i = control.GetStatus(classroom.Id, DateTime.Now.ToString("yyyy-MM-dd"), num); // string command = control.GetControlCommand(classroom.Id, DateTime.Now.ToString("yyyy-MM-dd"), num); // Thr t = new Thr(classroom, num, sender, i); // ThreadPool.QueueUserWorkItem(t.ThreadProc, command); } }
public event EventHandler<ClassrooomEventArgs> TimeToDo; //自定义一个事件,用于给设备发送信息 private void CurTimeToOper(object sender, EventArgs e) { Console.WriteLine(DateTime.Now.ToString("HH.mm")); DateTime now = DateTime.Now; //确定是哪节课 for (int i = 0; i < Config.Config.course.Length / Config.Config.course.Rank; i++) { if (Config.Config.Courses[i, 0] - new TimeSpan(0, 0, 10, 0) < now && Config.Config.Courses[i, 1] + new TimeSpan(0, 0, 5, 0) > now) { int classindex = i + 1; //是否是课前5分钟内或者是课后5分钟内 if (((Config.Config.Courses[i, 0] - new TimeSpan(0, 0, 10, 0) < now && Config.Config.Courses[i, 0] > now)) || ((Config.Config.Courses[i, 1] < now && Config.Config.Courses[i, 1] + new TimeSpan(0, 0, 5, 0) > now))) { ClassrooomEventArgs args = new ClassrooomEventArgs(); args.Rooms = allClassrooms; args.Num = classindex; TimeToDo?.Invoke(this, args); break; } } } }