#region 日志记录、支持其他线程访问
public delegate void LogAppendDelegate(Color color, string text);
/// <summary>
/// 追加显示文本
/// </summary>
/// <param name="color"></param>
/// <param name="text"></param>
public void LogAppend(Color color, string text)
{
revMsg.AppendText("\n");
revMsg.SelectionColor = color;
revMsg.AppendText(text);
}
/// <summary>
/// 显示错误信息
/// </summary>
/// <param name="text"></param>
public void LogError(string text)
{
LogAppendDelegate la = new LogAppendDelegate(LogAppend);
revMsg.Invoke(la, Color.Red, DateTime.Now.ToString("HH:mm:ss") + ":" + text);
}
/// <summary>
/// 显示正确信息
/// </summary>
/// <param name="text"></param>
public void LogRight(string text)
{
LogAppendDelegate la = new LogAppendDelegate(LogAppend);
revMsg.Invoke(la, Color.Green, DateTime.Now.ToString("HH:mm:ss") + ":" + text);
}
/// <summary>
/// 显示普通信息
/// </summary>
/// <param name="text"></param>
public void LogMessage(string text)
{
LogAppendDelegate la = new LogAppendDelegate(LogAppend);
revMsg.Invoke(la, Color.Black, DateTime.Now.ToString("HH:mm:ss") + ":" + text);
}
#endregion
转载于:https://my.oschina.net/dukson/blog/272338