public void Run(IMessengerWindow iMWindow) { try { doneEvent = new AutoResetEvent(false); ThreadParameter parameter = new ThreadParameter(); parameter.doneEvent = this.doneEvent; parameter.IMWindow = iMWindow; saveThread = new Thread(new ParameterizedThreadStart(this.SaveHistroyMethod)); saveThread.Start(parameter); } catch (COMException comExp) { logger.Error(comExp); } catch (Exception exp) { logger.Error(exp); } }
private void SaveHistroyMethod(object obj) { ThreadParameter para = (ThreadParameter)obj; IMessengerConversationWnd wnd = para.IMWindow as IMessengerConversationWnd; string history = string.Empty; while (isRuning) { try { if (wnd != null && !string.IsNullOrEmpty(wnd.History) && (savedMessageWordsCount != wnd.History.Length)) { history = wnd.History; savedMessageWordsCount = history.Length; if (this.SaveHistroyEvent != null) { lock (this.SaveHistroyEvent) { this.SaveHistroyEvent(this, history); } } } } catch (COMException comExp) { //logger.Warn(exp); Console.WriteLine(comExp); } catch (Exception exp) { logger.Error(exp); this.isRuning = false; } Thread.Sleep(200); } para.doneEvent.Set(); }