I use the following code to open a window in a separate thread
public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); } private void button1_Click(object sender, RoutedEventArgs e) { Thread newWindowThread = new Thread(new ThreadStart(() => {
If I use this code in a method, it works. But when I use it as follows, I get an error:
public partial class App : Application { #region Instance Variables private Thread newWindowThread; #endregion protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); newWindowThread = new Thread(new ThreadStart(() => {
It produces the following error:
System.Threading.ThreadStateException The state of the thread was not valid to execute the operation
What is the reason for this?
multithreading c # wpf
Cyberguille
source share