private void OnLogDataReceived(object sendor, LogDataReceivedEventArgs args) { if (args == null || args.Log == null) { return; } ILogData logData = args.Log; //lock (_writerLock) //{ // try // { // if (this.m_isRecording && (this._writer != null)) // { // this.CheckLogDataSize(); // if (this.m_writeSourceBufferName) // { // this._writer.WriteLine(string.Format("[{0}] [{1}:] {2}", logData.LocalTimestamp.ToString("MM-dd HH:mm:ss.fff"), logData.SourceBuffer, logData.ToString(this.OutputFormat, this.TimestampMode))); // } // else // { // this._writer.WriteLine(string.Format("[{0}] {1}", logData.LocalTimestamp.ToString("MM-dd HH:mm:ss.fff"), logData.ToString(this.OutputFormat, this.TimestampMode))); // } // this.m_logIndex++; // this._writer.Flush(); // } // //if (this.LogDataReceivedEvent != null) // //{ // // this.LogDataReceivedEvent(this, args); // //} // } // catch (Exception) // { // if (_writer != null) // { // _writer.Close(); // _writer.Dispose(); // } // } //} _receivedLogQueue.Add(logData); }
/// <summary> /// Lanch adb.exe by logcat command argument /// </summary> /// <param name="arguments">arguments</param> public void Start(string arguments) { Arguments = arguments; Action adbAction = () => { IsCanel = false; Process adbProc = new Process(); adbProc.StartInfo = new ProcessStartInfo() { Arguments = Arguments, UseShellExecute = false, CreateNoWindow = true, FileName = ADBFullName, //StandardOutputEncoding = Encoding.GetEncoding("utf-8"), StandardOutputEncoding = Encoding.GetEncoding("ISO-8859-1"), RedirectStandardOutput = true, }; adbProc.Exited += (sendor, e) => { _isKilled = true; }; _killAdbProc = () => { if (_isKilled == false) { adbProc.Kill(); } }; try { _isKilled = false; adbProc.Start(); using (StreamReader sr = adbProc.StandardOutput) { while (!IsCanel && !adbProc.HasExited) { string log = sr.ReadLine(); if (string.IsNullOrWhiteSpace(log) == true) { continue; } if (log.Contains("\\r\\n")) { log = log.Replace("\\r\\n", "\\n"); } if (LogDataReceived != null) { ILogData logData = new LogData(); logData.Data = log; LogDataReceivedEventArgs args = new LogDataReceivedEventArgs(); args.Log = logData; LogDataReceived(this, args); } } } } finally { adbProc.WaitForExit(); adbProc.Close(); } }; Task.Factory.StartNew(adbAction).Start(); }