public void OnFactorChange() { /*interrupt e thread. and receive will return -1, * the process function will returned and release Sema another new process thread * and e thread will be start soon*/ this.e.IsBackground = true; this.e.Interrupt(); ProcessSema.WaitOne(); Reset(); ProcessSema.Release(); }
protected override void ProcessData() { base.ProcessData(); string receiveData; var reLen = Receiver.ReadRecevieData(out receiveData); if (reLen == -1)//reLen==-1 means that Thread.Interrup has been called in somewhere,just return this function end thread { return; } if (reLen > 0) { JObject jobj = null; try { jobj = JObject.Parse(receiveData); } catch (Exception ex) { jobj = null; Debuger.PrintStr(ex.Message, EPRINT_TYPE.ERROR); } if (jobj == null) { Debuger.PrintStr("Parse Json string fail!", EPRINT_TYPE.WARNING); goto ReturnPoint; } EDataHeader header = (EDataHeader)int.Parse(jobj["type"].ToString()); //string message_id = jobj["msg_id"].ToString(); JsonObject jstr = null; if (jstr != null) { if (CurrentPair.app != null) { CurrentPair.app.Sender.WriteSendData(jstr.jstr); } this.Sender.WriteSendData(jstr.jstr); } } else { ReceiveZeroDisconnect = true; } ReturnPoint :; CurrentSemaCount = ProcessSema.Release(); }
protected override void ProcessData() { base.ProcessData(); string receiveData; var relen = Receiver.ReadRecevieData(out receiveData); if (relen == -1)/*reLen==-1 means that Thread.Interrup has been called in somewhere,just return this function end thread*/ { return; } if (relen > 0) { JObject jobj = JObject.Parse(receiveData); if (jobj == null) { Debuger.PrintStr("Parse Json string fail!", EPRINT_TYPE.WARNING); return; } EDataHeader header = (EDataHeader)int.Parse(jobj["type"].ToString()); JsonObject jstr = null; if (jstr != null) { this.Sender.WriteSendData(jstr.jstr); CurrentPair.sl.Sender.WriteSendData(jstr.jstr); } } else { ReceiveZeroDisconnect = true; } ReturnPoint :; if (ProcessSema != null) { CurrentSemaCount = ProcessSema.Release(); Debuger.PrintStr("release", EPRINT_TYPE.NORMAL); } }