using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using AGV_WPF_Global; using System.Threading; namespace AGV_WPF { public partial class SleepAndWakeUpForm : Form { private delegate void InvokeDelegate(); List listAll = new List(); int ActionCode = 0; Thread t; bool b = true; public SleepAndWakeUpForm() { InitializeComponent(); for (int i = 1; i <= Convert.ToUInt32(System.Configuration.ConfigurationManager.AppSettings["AGVNUM_MAX"]); i++) { listAll.Add(i); } } private void SleepAndWakeUpForm_Load(object sender, EventArgs e) { if (GlobalPara.IsOneKeySleep) { label1.Text = label1.Text.Replace("key", "休眠"); ActionCode = 0x20; } else { label1.Text = label1.Text.Replace("key", "唤醒"); ActionCode = 0x30; } this.FormClosed += new FormClosedEventHandler(SleepAndWakeUpForm_FormClosed); //timer1.Interval = 200; //timer1.Tick += new EventHandler(timer1_Tick); //timer1.Enabled = true; //timer1.Start(); t = new Thread(new ThreadStart(update)); t.Start(); } void SleepAndWakeUpForm_FormClosed(object sender, FormClosedEventArgs e) { //throw new NotImplementedException(); b = false; } void update() { try { while (b) { textBox1.Invoke(new InvokeDelegate(delegate { if (GlobalPara.IsOneKeySleep) { textBox1.Text = string.Join(",", listAll.Except(GlobalPara.SleepAGVNumList).ToArray()); } else { textBox1.Text = string.Join(",", listAll.Except(GlobalPara.WakeUpAGVNumList).ToArray()); } } )); Thread.Sleep(200); } } catch (Exception) { } } void timer1_Tick(object sender, EventArgs e) { //throw new NotImplementedException(); // textBox1.Invoke(new InvokeDelegate(delegate { if (GlobalPara.IsOneKeySleep) { textBox1.Text = string.Join(",", listAll.Except(GlobalPara.SleepAGVNumList).ToArray()); } else { textBox1.Text = string.Join(",", listAll.Except(GlobalPara.WakeUpAGVNumList).ToArray()); } } // )); //if (GlobalPara.IsOneKeySleep) //{ // if (GlobalPara.WakeUpAGVNumList.Count == 0) // { // MessageBox.Show("已休眠所有AGV"); // this.timer1.Tick -= timer1_Tick; // this.timer1.Stop(); // this.Close(); // } //} //else //{ // if (GlobalPara.SleepAGVNumList.Count == 0) // { // MessageBox.Show("已唤醒所有AGV"); // this.timer1.Tick -= timer1_Tick; // this.timer1.Stop(); // this.Close(); // } //} } private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Length > 0) { string[] text = textBox1.Text.Split(','); foreach (string str in text) { AGV_WPF.Tools.DispatcherTool.ControlAllAgv(ActionCode, 0, int.Parse(str), true); } } } } }