I need the current window to show a custom MessageBox. I do this:
Window owner = System.Windows.Application.Current.MainWindow;
sometimes it works. Where it doesn’t work, I get this error:
System.InvalidOperationException: {"The calling thread cannot access this object because a different thread owns it."}
InnerException: null
Message: The calling thread cannot access this object because a different thread owns it.
Would a solution to be to kick this call off to a separate thread than the main thread? If so, how do I do that? Thanks.
You’ll need to use the Dispatcher and Invoke/BeginInvoke to marshal the call back to the UI thread: