Detecting whether on UI thread in WPF and Winforms

Don’t use if(Dispatcher.CurrentDispatcher.Thread == Thread.CurrentThread) { // Do something } Dispatcher.CurrentDispatcher will, if the current thread do not have a dispatcher, create and return a new Dispatcher associated with the current thread. Instead do like this Dispatcher dispatcher = Dispatcher.FromThread(Thread.CurrentThread); if (dispatcher != null) { // We know the thread have a dispatcher that we … Read more

assert vs. JUnit Assertions

In JUnit4 the exception (actually Error) thrown by a JUnit assert is the same as the error thrown by the java assert keyword (AssertionError), so it is exactly the same as assertTrue and other than the stack trace you couldn’t tell the difference. That being said, asserts have to run with a special flag in … Read more