private void AppendLog(string str, bool newline = true) { if (newline) { str += "\r"; } Dispatcher.Invoke(new Action(() => { LogViewer.AppendText(str); LogViewer.ScrollToEnd(); })); }