Created
October 28, 2013 20:40
-
-
Save anonymous/7204233 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Linq; | |
using System.Text; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Data; | |
using System.Windows.Documents; | |
using System.Windows.Input; | |
using System.Windows.Media; | |
using System.Windows.Media.Imaging; | |
using System.Windows.Navigation; | |
using System.Windows.Shapes; | |
namespace WpfApplication11 | |
{ | |
/// <summary> | |
/// Interaction logic for MainWindow.xaml | |
/// </summary> | |
public partial class MainWindow : Window | |
{ | |
public MainWindow() | |
{ | |
InitializeComponent(); | |
//WORKS | |
var window1 = new Window1(); | |
window1.Show(); | |
//DOESNT WORK | |
var bw = new BackgroundWorker(); | |
bw.DoWork += bw_DoWork; | |
bw.RunWorkerAsync(); | |
//WORKS AGAIN! | |
var bw2 = new BackgroundWorker(); | |
bw2.DoWork += bw_DoWork2; | |
bw2.RunWorkerAsync(); | |
} | |
void bw_DoWork(object sender, DoWorkEventArgs e) | |
{ | |
var window1 = new Window1(); | |
window1.Show(); | |
} | |
void bw_DoWork2(object sender, DoWorkEventArgs e) | |
{ | |
Application.Current.Dispatcher.Invoke((Action) delegate | |
{ | |
var window1 = new Window1(); | |
window1.Show(); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment