using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

namespace MultiDispatcherTest
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>
	public partial class App : Application
	{
		protected override void OnStartup(StartupEventArgs e)
		{
			Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;

			var entrance = new UIEntrance("Startup");
			entrance.Post(d => StartUpNewDispatcher(), null, null, true);
		}

		private async Task StartUpNewDispatcher()
		{
			var cal = 0;
			await TaskEx.Run(() =>
			{
				for (int i = 0; i < 100; i++)
				{
					Thread.Sleep(1);
					cal += i;
				}
			});

			var mainWindow = new MainWindow();
			mainWindow.Closed += (s, e) => System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
			mainWindow.Show();
		}
	}
}
