private void OnDataProcessing(object sender, ProcEventArgs args) { Invoke((MethodInvoker)(() => { //textBox2.AppendText("TESTING \n"); textBox2.Text = "TESTING"; })); }
public void Process(DataStorage ds) { procEventArgs = new ProcEventArgs(); procEventArgs.EvDataStorage = ds; procEventArgs.EvPercentCompleted = 0; Thread thread = new Thread(new ThreadStart(DoWork)); Console.WriteLine("The thread #" + Thread.CurrentThread.ManagedThreadId + " is started"); thread.Start(); }
protected virtual void OnDataProcessed(ProcEventArgs procEventArgs) { if (DataProcessed != null) { // Fire the OnDataProcessed event to subscripber(s) Console.WriteLine(this.ToString() + ": Sending the OnDataProcessed event to the subscripbers..."); DataProcessed(this, procEventArgs); Console.WriteLine(this.ToString() + ": The OnDataProcessed event is processed by the subscripbers"); } else { Console.WriteLine("No subscripber registerd!"); } }
protected virtual void OnDataProcessing(ProcEventArgs procEventArgs) { DataProcessing(this, procEventArgs); }
private void OnDataProcessed(object sender, ProcEventArgs args) { string dataRecive = args.EvDataStorage.Data.ToString(); string xmlPath = tbXMLformat.Text; string xmlString = System.IO.File.ReadAllText(xmlPath); //Console.WriteLine(dataRecive.Length); //if (dataRecive.Length == 95) if (dataRecive != null) { sRev = textBox3.Text; sPN = textBox4.Text; sPrinterIP = tbIP.Text; XmlDocument xm = new XmlDocument(); Invoke((MethodInvoker) delegate() { textBox2.AppendText(args.EvDataStorage.Data + Environment.NewLine); }); Regex regex = new Regex(@"[A-Z]\d\d\d\d\d\d\d\d\d\d\d\d"); Match match = regex.Match(dataRecive); if (match.Success) { //Console.WriteLine("MATCH VALUE: " + match.Value); sSN = match.Value; Invoke((MethodInvoker) delegate() { textBox1.Text = sSN; }); xmlString = xmlString.Replace("{{REV}}", sRev); xmlString = xmlString.Replace("{{PN}}", sPN); xmlString = xmlString.Replace("{{SN}}", sSN); xmlString = xmlString.Replace("{{PRINTER}}", sPrinterIP); Invoke((MethodInvoker) delegate() { textBox2.AppendText("==> Write File to Result folder" + Environment.NewLine); }); File.WriteAllText(Path.Combine("Result\\", "TEST.xml"), xmlString); if (sSN == SScanLabel) { Invoke((MethodInvoker) delegate() { textBox2.AppendText("==> Match Found !!! HWID กับ Label S/N เหมือนกัน ไม่จำเป็นต้องปิ้นใหม่" + Environment.NewLine); lbStatus.Text = "ไม่จำเป็นต้องปริ้น Label ใหม่"; lbStatus.BackColor = Color.GreenYellow; }); } else { Invoke((MethodInvoker) delegate() { textBox2.AppendText("==> HWID and Scanlabel S/N are not match. จำเป็นต้องปิ้น Label ใหม่" + Environment.NewLine); lbStatus.Text = "ปริ้น Label ใหม่"; lbStatus.BackColor = Color.Red; button2.Enabled = true; }); } } else { Invoke((MethodInvoker) delegate() { textBox2.AppendText("==> Error กรูณา insert ตัวงานอีกครั้ง" + Environment.NewLine); }); //DataStorage dataStorage = new DataStorage(); //DataProcessor dataProcessor = new DataProcessor(); //dataProcessor.sPort = sPort; //// Subscripber A, the SubscripberClass //// Subscripber B, this form //dataProcessor.DataProcessing += this.OnDataProcessing; //dataProcessor.DataProcessed += this.OnDataProcessed; //// Start process the data //dataProcessor.Process(dataStorage); } // xm.LoadXml(xmlString); //XML.WriteToXmlFile("TEST.xml", xm,true); //.WriteAllText("C:\\Test.xml", xmlString); } else { Invoke((MethodInvoker) delegate() { textBox2.AppendText("==> Error กรูณา insert ตัวงานอีกครั้ง" + Environment.NewLine); }); //DataStorage dataStorage = new DataStorage(); //DataProcessor dataProcessor = new DataProcessor(); //dataProcessor.sPort = sPort; //// Subscripber A, the SubscripberClass //// Subscripber B, this form //dataProcessor.DataProcessing += this.OnDataProcessing; //dataProcessor.DataProcessed += this.OnDataProcessed; //// Start process the data //dataProcessor.Process(dataStorage); } }