コード例 #1
0
        public static async Task ShowWaittingMessge(Action action, Action closeAction = null)
        {
            await Application.Current.Dispatcher.Invoke(async() =>
            {
                if (CheckOpen())
                {
                    return(null);
                }

                var view = new WaittingMessageDialog();

                //show the dialog
                return(await DialogHost.ShowWithOpen(view, "windowDialog", (l, e) =>
                {
                    Task.Run(action).ContinueWith(m =>
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            e.Session.Close(false);

                            closeAction?.Invoke();
                        });
                    });
                }));
            });
        }
コード例 #2
0
        /// <summary> 带有返回结果的等待消息窗口 </summary>
        public static async Task <T> ShowWaittingResultMessge <T>(Func <T> action)
        {
            if (CheckOpen() || action == null)
            {
                return(default(T));
            }

            T result = default(T);

            await Application.Current.Dispatcher.Invoke(async() =>
            {
                var view = new WaittingMessageDialog();

                //show the dialog
                await DialogHost.ShowWithOpen(view, "windowDialog", (l, e) =>
                {
                    Task.Run(() => result = action.Invoke()).ContinueWith(m =>
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            e.Session.Close(false);
                        });
                    });
                });
            });

            return(result);
        }