Using Dispatcher to update values in GUI elements from a background thread

System.InvalidOperationException'

Quick tip:
If you’re developing something like a WPF app and you’ll need to update values on the User Interface based on a long-running operation that runs in a background thread (like depicted here), you’ll probably need to use Dispatcher, or otherwise you’ll run into issues with the GUI elements being owned by another thread, and therefore forbidding access to them. This can result in an error like this:

Luckily, there’s a quick workaround available. Read on!

Cue the Dispatcher

Continue reading

Simplest way to create a thread on SharePoint

Stock photo from pixabay.com

This post describes the (probably) easiest and most straightforward way of creating a new Thread in your SharePoint (or any other .NET) server-side / desktop code.

Solution: how to create a Thread

Let’s face it – one should not create new Threads lightly when developing SharePoint solutions, but sometimes it’s difficult to avoid. This one time we were developing a pretty simple functionality, where we needed to create a few fields on a certain title when user activated a feature. However, because of the complexity of the environment, we encountered problems changing the title of the new field. Now, it’s usually pretty simple, but this time some other functionality, most likely developed by someone else, was changing it to the internal field name – which doesn’t look to good.

To be honest, we’re not even sure, why this worked. We suspected it might be because of the current culture of the thread, but changing it didn’t have any effect. Any way, we’re glad this worked, whatever the reason for that is.