Пример #1
0
        async Task CreateNewPageAsync(IPageSettingsModel settings)
        {
            await Task.Run(() =>
            {
                var context = new PageContext(Application, settings.Title);
                if (context.PageNotFound())
                {
                    var sw = Stopwatch.StartNew();

                    AddJournalPageContent(context,
                                          context.CreateNewPage(), settings);

                    context.NavigateToPage();
                    RunKeyboardMacro();

                    Tracer.WriteInfoLine("CreateNewPageAsync elapsed time: {0} ms",
                                         sw.ElapsedMilliseconds);
                    //DEBUG*/ context.SaveCurrentPageToDisk();
                    //DEBUG*/ context.SendCurrentPageToClipboard();
                }
                else
                {
                    context.NavigateToPage();
                    ScrollToBottomOfPage();
                }
            }).ConfigureAwait(false);
        }
Пример #2
0
        Task CreateNewPageTask(IPageSettingsModel settings)
        {
            Action action = () =>
            {
                var context = new PageContext(Application, settings.Title);
                if (context.PageNotFound())
                {
                    AddJournalPageContent(context,
                                          context.CreateNewPage(), settings);

                    context.NavigateToPage();
                    RunKeyboardMacro();

                    //DEBUG*/ context.SaveCurrentPageToDisk();
                    //DEBUG*/ context.SendCurrentPageToClipboard();
                }
                else
                {
                    context.NavigateToPage();
                    ScrollToBottomOfPage();
                }
            };

            var tcs    = new TaskCompletionSource <object>();
            var thread = new Thread(() =>
            {
                try
                {
                    action();
                    tcs.SetResult(null);
                }
                catch (Exception e)
                {
                    tcs.SetException(e);
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            return(tcs.Task);
        }