Beispiel #1
0
        public async Task TestRunOn()
        {
            var taskSchedulerId = TaskScheduler.Current.Id;

            Log.Info().WriteLine("Current id: {0}", taskSchedulerId);
            UiContext.Initialize();

            var window = new Window
            {
                Width  = 200,
                Height = 200
            };

            window.Show();

            // Should not throw anything
            window.Focus();

            // Make sure the current task scheduler is not for the UI thread
            await Task.Delay(10).ConfigureAwait(false);

            // Should throw
            Assert.Throws <InvalidOperationException>(() => window.Focus());

            // This should also not throw anything
            await UiContext.RunOn(() =>
            {
                var taskSchedulerIdInside = TaskScheduler.Current.Id;
                Log.Info().WriteLine("Current id inside: {0}", taskSchedulerIdInside);
                Assert.NotEqual(taskSchedulerId, taskSchedulerIdInside);
                window.Close();
            });
        }
Beispiel #2
0
        /// <summary>
        ///     Make sure we startup everything after WPF instanciated
        /// </summary>
        /// <param name="e">StartupEventArgs</param>
        protected override async void OnStartup(StartupEventArgs e)
        {
            // Enable UI access for different Dapplo packages, especially the UiContext.RunOn
            // This only works here, not before the Application is started and not later
            UiContext.Initialize();

            _bootstrapper.Configure();

            // Register the UI SynchronizationContext, this can be retrieved by specifying the name "ui" for the argument
            _bootstrapper.Builder.RegisterInstance(SynchronizationContext.Current).Named <SynchronizationContext>("ui");
            _bootstrapper.Builder.RegisterInstance(TaskScheduler.FromCurrentSynchronizationContext()).Named <TaskScheduler>("ui");

            // Prepare the bootstrapper
            await _bootstrapper.InitializeAsync().ConfigureAwait(true);

            // The following makes sure that Caliburn.Micro is correctly initialized on the right thread and Execute.OnUIThread works
            // Very important to do this, after all assemblies are loaded!
            _caliburnMicroBootstrapper = new CaliburnMicroBootstrapper(_bootstrapper);
            _caliburnMicroBootstrapper.Initialize();

            // Now check if there is a lock, if so we invoke OnAlreadyRunning and return
            if (_bootstrapper.IsAlreadyRunning)
            {
                var exitCode = OnAlreadyRunning?.Invoke() ?? -1;
                Shutdown(exitCode);
                return;
            }

            // Start Dapplo, do not use configure-await false here, so the OnStartup doesn't have any issues
            await _bootstrapper.StartupAsync().ConfigureAwait(true);

            // This also triggers the Caliburn.Micro.BootstrapperBase.OnStartup
            base.OnStartup(e);
        }
Beispiel #3
0
        /// <summary>
        /// 画面ロード時のイベントです
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void OnLoad(object sender, EventArgs e)
        {
            UiContext.Initialize();

            ResourceManager.Instance.MainForm = this;

            Program.ActionTermOutTimerEventOnCompleted -= this.ActionTermOutTimerEventOnCompleted;
            Program.ActionTermOutTimerEventOnCompleted += this.ActionTermOutTimerEventOnCompleted;

            this.DgvAllTasks.Initialize(true);
            this.DgvRecentTasks.Initialize(false);

            this.DgvAllTasks.UpdateEvent    += this.DgvAllTasksOnUpdateEvent;
            this.DgvRecentTasks.UpdateEvent += this.DgvRecentTasksOnUpdateEvent;

            this.ShowAllTaskListInDgvAllTasks();
            this.DgvAllTasksOnUpdateEvent(null, null);

            this.InitializeGroupList();

            this.TxtFilter.TextChanged += this.TxtFilter_OnTextChanged;

            this.UpdateCurrentDateTime();
        }