using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
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;
using System.Windows.Threading;
namespace 別スレッドでポップアップ表示
{
/// <summary>
/// 参照リソース
/// http://reedcopsey.com/2011/11/28/launching-a-wpf-window-in-a-separate-thread-part-1/
/// https://eprystupa.wordpress.com/2008/07/28/running-wpf-application-with-multiple-ui-threads/
/// http://stackoverflow.com/questions/1111369/how-do-i-create-and-show-wpf-windows-on-separate-threads
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Btn1_Click(object sender, RoutedEventArgs e)
{
var t = new Thread(() =>
{
SynchronizationContext.SetSynchronizationContext(
new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher)
);
var newWindow = new Popup1();
newWindow.Closed += (o, args) =>
{
Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
};
newWindow.Topmost = true;
newWindow.Show();
Dispatcher.Run();
});
t.SetApartmentState(ApartmentState.STA);
t.IsBackground = true;
t.Start();
}
}
}