System.Threading.Tasks.TaskCompletionSource.SetResult(SignalWindowsFrontend)

Here are the examples of the csharp api System.Threading.Tasks.TaskCompletionSource.SetResult(SignalWindowsFrontend) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 Source : App.xaml.cs
with GNU General Public License v3.0
from signal-csharp

private async Task CreateSecondaryWindowOrShowMain(ActivationViewSwitcher switcher, string conversationId)
        {
            Logger.LogInformation("CreateSecondaryWindow()");
            CoreApplicationView newView = CoreApplication.CreateNewView();
            int newViewId = 0;
            var frontendCreationCompletionSource = new TaskCompletionSource<SignalWindowsFrontend>();
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                SignalWindowsFrontend swf = null;
                try
                {
                    Frame frame = new Frame();
                    frame.Navigate(typeof(MainPage), conversationId);
                    Window.Current.Content = frame;
                    Window.Current.Activate();
                    var currView = ApplicationView.GetForCurrentView();
                    if (GlobalSettingsManager.BlockScreenshotsSetting)
                    {
                        currView.IsScreenCaptureEnabled = false;
                    }
                    currView.Consolidated += CurrView_Consolidated;
                    newViewId = currView.Id;
                    ViewModelLocator newVML = (ViewModelLocator)Resources["Locator"];
                    SetupTopBar();
                    swf = new SignalWindowsFrontend(newView.Dispatcher, newVML, newViewId);
                }
                catch (Exception e)
                {
                    Logger.LogError("CreateSecondaryWindowOrShowMain() SignalWindowsFrontend creation failed: {0}\n{1}", e.Message, e.StackTrace);
                }
                finally
                {
                    frontendCreationCompletionSource.SetResult(swf);
                }
            });
            var frontend = await frontendCreationCompletionSource.Task;
            var addFrontendCompletionSource = new TaskCompletionSource<bool>();
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                bool addFrontendResult = false;
                try
                {
                    //AddFrontend blocks for the handle lock, but the new window is not yet registered, so nothing will be invoked
                    addFrontendResult = Handle.AddFrontend(frontend.Dispatcher, frontend);
                }
                catch (Exception e)
                {
                    Logger.LogError("CreateSecondaryWindowOrShowMain() AddFrontend() failed: {0}\n{1}", e.Message, e.StackTrace);
                }
                finally
                {
                    addFrontendCompletionSource.SetResult(addFrontendResult);
                }
            });
            var success = await addFrontendCompletionSource.Task;
            if (success)
            {
                Views.Add(newViewId, frontend);
                DisappearingMessagesManager.AddFrontend(frontend.Dispatcher, frontend);
                await switcher.ShowreplacedtandaloneAsync(newViewId);
                Logger.LogInformation("CreateSecondaryWindow() added view {0}", newViewId);
            }
            else
            {
                Logger.LogInformation("CreateSecondaryWindow() showing MainView {0}", MainViewId);
                await switcher.ShowreplacedtandaloneAsync(MainViewId);
            }
        }