Created
July 7, 2016 02:21
-
-
Save zhenlinyang/221f1978953e6ff0020306494900d1a9 to your computer and use it in GitHub Desktop.
Make Thread-Safe Calls to Windows Forms Controls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public delegate void LogCallback(string str, Color color); | |
private void LogHandler(string str, Color color) | |
{ | |
if (LogRichTextBox.InvokeRequired) | |
{ | |
LogCallback logCallback = LogCallbackFunction; | |
Invoke(logCallback, new object[] {str, color}); | |
} | |
else | |
{ | |
LogCallbackFunction(str, color); | |
} | |
} | |
private void LogCallbackFunction(string str, Color color) | |
{ | |
LogRichTextBox.SelectionFont = new Font(FontFamily.GenericMonospace, 12, FontStyle.Regular); | |
LogRichTextBox.SelectionColor = color; | |
LogRichTextBox.AppendText(str); | |
LogRichTextBox.AppendText("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment