private void CreateAndStartAppDomain()
        {
            var info = new AppDomainSetup {
                ApplicationBase = LauncherConstants.ApplicationBasePath
            };

            _appDomain = AppDomain.CreateDomain("LauncherWaitDialog", null, info);

            // Since we may execute this code from an embedded assembly typeof().Assembly.Location might return "".
            // Thus we need to tell the AppDomain where to look at on disk.
            var location = Path.Combine(LauncherConstants.ApplicationBasePath, GetType().Assembly.GetName().Name) + ".dll";

            if (!File.Exists(location))
            {
                throw new FileNotFoundException("Required assembly not found!", location);
            }

            var provider = (WaitDialogWindowInternalService)_appDomain.CreateInstanceFromAndUnwrap(location, typeof(WaitDialogWindowInternalService).FullName);

            _provider = provider;
            if (_provider == null)
            {
                throw new InvalidOperationException("Could not create WaitDialogWindowInternal");
            }
            _provider.Initialize(_initializationArguments, _cancelHandler);
        }
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (disposing)
            {
                _provider?.Dispose();
                _provider = null;

                if (Application.Current?.MainWindow != null)
                {
                    Application.Current.MainWindow.Closed -= OnApplicationExit;
                }

                AppDomain.Unload(_appDomain);
            }
            _disposed = true;
        }