public threadMsg(IAPI api, EventHandler <threadMsgEventArgs> on_message = null) { onMessageComplete = on_message; _api = api; _resetEvent = new ManualResetEvent(false); _threadEvent = new ManualResetEvent(false); _thread = new Thread(new ParameterizedThreadStart(delegate(object evt) { api.Init(); api.Open = true; app.postToAPI(_API.MEDIA, _API.MEDIA_KEY_INITED, null); threadMsgPara tm = (threadMsgPara)evt; while (_exit == false) { tm.ResetEvent.WaitOne(); if (_exit) { break; } else { msg m = api.Execute(_msg); //if (onMessageComplete != null) onMessageComplete.Invoke(this, new threadMsgEventArgs(m)); } tm.ResetEvent.Reset(); } })); _thread.Start(new threadMsgPara(_resetEvent)); }
public threadMsg(IAPI api, EventHandler <threadMsgEventArgs> on_message = null) { onMessageComplete = on_message; _api = api; _resetEvent = new ManualResetEvent(false); _threadEvent = new ManualResetEvent(false); _thread = new Thread(new ParameterizedThreadStart(delegate(object evt) { threadMsgPara tm = (threadMsgPara)evt; while (_exit == false) { tm.ResetEvent.WaitOne(); if (_exit == false) { msg m = api.Execute(_msg); //if (onMessageComplete != null) onMessageComplete.Invoke(this, new threadMsgEventArgs(m)); } tm.ResetEvent.Reset(); } })); _thread.Start(new threadMsgPara(_resetEvent)); }