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

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

Java/ JUnit – AssertTrue vs AssertFalse

assertTrue will fail if the second parameter evaluates to false (in other words, it ensures that the value is true). assertFalse does the opposite. assertTrue(“This will succeed.”, true); assertTrue(“This will fail!”, false); assertFalse(“This will succeed.”, false); assertFalse(“This will fail!”, true); As with many other things, the best way to become familiar with these methods is …

Read more

Why should I use asserts?

First, the performance difference can be huge. In one project our asserts literally caused a 3x slowdown. But they helped us uncover some really pesky bugs. Which is exactly the point. Asserts are there to help you catch bugs. And because they are removed in release builds, we can afford to put a lot of …

Read more