Always open sync dialogs on the UI thread sync
authorThomas
Mon, 07 Oct 2019 16:58:48 +0200
branchsync
changeset 27979dadc302b32b
parent 2796 82b886ee1e83
child 2798 484bde7d2e9b
Always open sync dialogs on the UI thread
ThisAddIn.cs
UI/Views/DialogWindow.xaml.cs
     1.1 --- a/ThisAddIn.cs	Mon Oct 07 16:08:39 2019 +0200
     1.2 +++ b/ThisAddIn.cs	Mon Oct 07 16:58:48 2019 +0200
     1.3 @@ -1,6 +1,7 @@
     1.4  ´╗┐using Microsoft.Win32;
     1.5  using pEp.Extensions;
     1.6  using pEp.UI;
     1.7 +using pEp.UI.Views;
     1.8  using pEpCOMServerAdapterLib;
     1.9  using System;
    1.10  using System.Collections.Generic;
    1.11 @@ -2698,8 +2699,8 @@
    1.12              CultureInfo.DefaultThreadCurrentUICulture = culture;
    1.13              Log.Info("ThisAddIn_Startup: " + culture.TwoLetterISOLanguageName + " language detected.");
    1.14  
    1.15 -            // Add reference to KeySyncWizard in order to start the dialog from the main thread
    1.16 -            KeySyncWizard.Wizard = new KeySyncWizard();
    1.17 +            // Create UI thread dispatcher to open dialog windows
    1.18 +            DialogWindow.UIThreadDispatcher = new DialogWindow()?.Dispatcher;
    1.19  
    1.20              try
    1.21              {
     2.1 --- a/UI/Views/DialogWindow.xaml.cs	Mon Oct 07 16:08:39 2019 +0200
     2.2 +++ b/UI/Views/DialogWindow.xaml.cs	Mon Oct 07 16:58:48 2019 +0200
     2.3 @@ -5,6 +5,7 @@
     2.4  using System.Collections.Generic;
     2.5  using System.ComponentModel;
     2.6  using System.Windows;
     2.7 +using System.Windows.Threading;
     2.8  
     2.9  namespace pEp.UI.Views
    2.10  {
    2.11 @@ -13,6 +14,12 @@
    2.12      /// </summary>
    2.13      internal partial class DialogWindow : Window
    2.14      {
    2.15 +        /* In order to always open this window on the UI thread,
    2.16 +         * we store a reference to a window's dispatcher. Invoking
    2.17 +         * this dispatcher marshals the call to the UI thread.
    2.18 +         */ 
    2.19 +        public static Dispatcher UIThreadDispatcher = null;
    2.20 +
    2.21          /// <summary>
    2.22          /// Primary constructor.
    2.23          /// </summary>
    2.24 @@ -130,13 +137,13 @@
    2.25          /// <param name="partnerIdentities">The partner identities.</param>
    2.26          public static void CreateAndShow(Dialog.Type type, PEPIdentity myself, List<PEPIdentity> partnerIdentities)
    2.27          {
    2.28 -            Extensions.TaskExtensions.StartSTATask(() =>
    2.29 +            DialogWindow.UIThreadDispatcher?.Invoke(() =>
    2.30              {
    2.31 -                // Create the dialog
    2.32 -                DialogWindow dialogWindow = new DialogWindow(new Dialog(type, myself, partnerIdentities));
    2.33 +                if (type == Dialog.Type.KeySync)
    2.34 +                {
    2.35 +                    // Create the dialog
    2.36 +                    DialogWindow dialogWindow = new DialogWindow(new Dialog(type, myself, partnerIdentities));
    2.37  
    2.38 -                if (type != Dialog.Type.Handshake)
    2.39 -                {
    2.40                      // Connect the action to handle sync handshake signals
    2.41                      AdapterCallbacks.SyncHandshakeSignalAction = dialogWindow.SyncHandshakeSignalReceivedAction;
    2.42  
    2.43 @@ -145,7 +152,7 @@
    2.44                  }
    2.45                  else
    2.46                  {
    2.47 -                    dialogWindow.Show();
    2.48 +                    Log.Error("CreateAndShow: Dialog type {0} not implemented.", Enum.GetName(typeof(Dialog.Type), type));
    2.49                  }
    2.50              });
    2.51          }