Melursus
Melursus

Reputation: 10608

WPF - Initializing Window.Owner to a Window created on a different thread

The window _splash is created on a different thread.

MainWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
MainWindow.Owner = _splash; // Throw: The calling thread cannot access this object because a different thread owns it

How can I make this code work ?

Upvotes: 2

Views: 1034

Answers (2)

Ben Straub
Ben Straub

Reputation: 5776

  1. Don't do any long-running work on the UI thread. Use BackgroundWorkers or something like ReactiveExtensions to make this easy.
  2. Create all Window instances on the UI thread.

Upvotes: 0

Chris Shain
Chris Shain

Reputation: 51359

Not to sound crass, but you fix it by running the splash screen on the UI thread running the main window. Why does the splash screen need its own thread?

Upvotes: 1

Related Questions