From 629534a19e21bae5cad3926d9f568a08a5ab05bd Mon Sep 17 00:00:00 2001 From: Peter Simpson <38855929+Peter-Simpson@users.noreply.github.com> Date: Tue, 22 Dec 2020 10:13:14 +0000 Subject: [PATCH] Make initial Chooser discovery synchronous / asynchronous behaviour configurable --- ...ChooserAlpacaConfigurationForm.Designer.vb | 25 +++++++++++++++---- .../ChooserAlpacaConfigurationForm.vb | 3 ++- .../ASCOM.Utilities/ChooserForm.vb | 19 +++++++------- .../Installer Project/ascom platform 6.mpr | 2 +- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/ASCOM.Utilities/ASCOM.Utilities/ChooserAlpacaConfigurationForm.Designer.vb b/ASCOM.Utilities/ASCOM.Utilities/ChooserAlpacaConfigurationForm.Designer.vb index 85f350749..26cf911bf 100644 --- a/ASCOM.Utilities/ASCOM.Utilities/ChooserAlpacaConfigurationForm.Designer.vb +++ b/ASCOM.Utilities/ASCOM.Utilities/ChooserAlpacaConfigurationForm.Designer.vb @@ -42,6 +42,7 @@ Partial Class ChooserAlpacaConfigurationForm Me.RadIpV4AndV6 = New System.Windows.Forms.RadioButton() Me.RadIpV6 = New System.Windows.Forms.RadioButton() Me.RadIpV4 = New System.Windows.Forms.RadioButton() + Me.ChkMultiThreadedChooser = New System.Windows.Forms.CheckBox() CType(Me.NumDiscoveryIpPort, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.NumDiscoveryBroadcasts, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.NumDiscoveryDuration, System.ComponentModel.ISupportInitialize).BeginInit() @@ -52,7 +53,8 @@ Partial Class ChooserAlpacaConfigurationForm ' 'BtnOK ' - Me.BtnOK.Location = New System.Drawing.Point(519, 303) + Me.BtnOK.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) + Me.BtnOK.Location = New System.Drawing.Point(516, 311) Me.BtnOK.Name = "BtnOK" Me.BtnOK.Size = New System.Drawing.Size(75, 23) Me.BtnOK.TabIndex = 5 @@ -61,8 +63,9 @@ Partial Class ChooserAlpacaConfigurationForm ' 'BtnCancel ' + Me.BtnCancel.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.BtnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel - Me.BtnCancel.Location = New System.Drawing.Point(601, 303) + Me.BtnCancel.Location = New System.Drawing.Point(598, 311) Me.BtnCancel.Name = "BtnCancel" Me.BtnCancel.Size = New System.Drawing.Size(75, 23) Me.BtnCancel.TabIndex = 6 @@ -134,9 +137,9 @@ Partial Class ChooserAlpacaConfigurationForm Me.Label3.AutoSize = True Me.Label3.Location = New System.Drawing.Point(291, 127) Me.Label3.Name = "Label3" - Me.Label3.Size = New System.Drawing.Size(201, 13) + Me.Label3.Size = New System.Drawing.Size(187, 13) Me.Label3.TabIndex = 8 - Me.Label3.Text = "Discovery Duration (Default 2.0 seconds)" + Me.Label3.Text = "Discovery Duration (Default 1 second)" ' 'PictureBox1 ' @@ -243,13 +246,24 @@ Partial Class ChooserAlpacaConfigurationForm Me.RadIpV4.Text = "IP V4 Only" Me.RadIpV4.UseVisualStyleBackColor = True ' + 'ChkMultiThreadedChooser + ' + Me.ChkMultiThreadedChooser.AutoSize = True + Me.ChkMultiThreadedChooser.Location = New System.Drawing.Point(269, 285) + Me.ChkMultiThreadedChooser.Name = "ChkMultiThreadedChooser" + Me.ChkMultiThreadedChooser.Size = New System.Drawing.Size(304, 17) + Me.ChkMultiThreadedChooser.TabIndex = 16 + Me.ChkMultiThreadedChooser.Text = "DIsplay Chooser while discovery is underway (Default true))" + Me.ChkMultiThreadedChooser.UseVisualStyleBackColor = True + ' 'ChooserAlpacaConfigurationForm ' Me.AcceptButton = Me.BtnOK Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.CancelButton = Me.BtnCancel - Me.ClientSize = New System.Drawing.Size(700, 338) + Me.ClientSize = New System.Drawing.Size(685, 346) + Me.Controls.Add(Me.ChkMultiThreadedChooser) Me.Controls.Add(Me.GrpIpVersion) Me.Controls.Add(Me.ChkShowCreateNewAlpacaDriverMessage) Me.Controls.Add(Me.Label4) @@ -300,4 +314,5 @@ Partial Class ChooserAlpacaConfigurationForm Friend WithEvents RadIpV4AndV6 As RadioButton Friend WithEvents RadIpV6 As RadioButton Friend WithEvents RadIpV4 As RadioButton + Friend WithEvents ChkMultiThreadedChooser As CheckBox End Class diff --git a/ASCOM.Utilities/ASCOM.Utilities/ChooserAlpacaConfigurationForm.vb b/ASCOM.Utilities/ASCOM.Utilities/ChooserAlpacaConfigurationForm.vb index 80b765391..7000e55e2 100644 --- a/ASCOM.Utilities/ASCOM.Utilities/ChooserAlpacaConfigurationForm.vb +++ b/ASCOM.Utilities/ASCOM.Utilities/ChooserAlpacaConfigurationForm.vb @@ -31,7 +31,7 @@ ChkShowDeviceDetails.Checked = chooserForm.AlpacaShowDeviceDetails NumExtraChooserWidth.Value = Convert.ToDecimal(chooserForm.AlpacaChooserIncrementalWidth) ChkShowCreateNewAlpacaDriverMessage.Checked = Not GetBool(SUPPRESS_ALPACA_DRIVER_ADMIN_DIALOGUE, SUPPRESS_ALPACA_DRIVER_ADMIN_DIALOGUE_DEFAULT) - + ChkMultiThreadedChooser.Checked = chooserForm.AlpacaMultiThreadedChooser ' Set the IP v4 / v6 radio boxes If chooserForm.AlpacaUseIpV4 And chooserForm.AlpacaUseIpV6 Then '// Both Then IPv4 And v6 are enabled so Set the "both" button RadIpV4AndV6.Checked = True @@ -58,6 +58,7 @@ chooserForm.AlpacaShowDeviceDetails = ChkShowDeviceDetails.Checked chooserForm.AlpacaChooserIncrementalWidth = Convert.ToInt32(NumExtraChooserWidth.Value) SetName(SUPPRESS_ALPACA_DRIVER_ADMIN_DIALOGUE, (Not ChkShowCreateNewAlpacaDriverMessage.Checked).ToString()) + chooserForm.AlpacaMultiThreadedChooser = ChkMultiThreadedChooser.Checked ' Set the IP v4 And v6 variables as necessary If (RadIpV4.Checked) Then ' The Then IPv4 radio button Is checked so Set the IP v4 And IP v6 variables accordingly diff --git a/ASCOM.Utilities/ASCOM.Utilities/ChooserForm.vb b/ASCOM.Utilities/ASCOM.Utilities/ChooserForm.vb index a22249d16..4d3fcc650 100644 --- a/ASCOM.Utilities/ASCOM.Utilities/ChooserForm.vb +++ b/ASCOM.Utilities/ASCOM.Utilities/ChooserForm.vb @@ -15,9 +15,6 @@ Friend Class ChooserForm #Region "Constants" - ' Debug constants - Private Const DEBUG_SINGLE_THREADING As Boolean = False ' If set TRUE, the Chooser form display will be suppressed until discovery completes, far from ideal, so normally leave FALSE - ' General constants Private Const ALERT_MESSAGEBOX_TITLE As String = "ASCOM Chooser" Private Const PROPERTIES_TOOLTIP_DISPLAY_TIME As Integer = 5000 ' Time to display the Properties tooltip (milliseconds) @@ -43,6 +40,7 @@ Friend Class ChooserForm Private Const ALPACA_CHOOSER_WIDTH As String = "Alpaca Chooser width" : Private Const ALPACA_CHOOSER_WIDTH_DEFAULT As Integer = 0 Private Const ALPACA_USE_IPV4 As String = "Use IPv4" : Private Const ALPACA_USE_IPV4_DEFAULT As Boolean = True Private Const ALPACA_USE_IPV6 As String = "Use IPv6" : Private Const ALPACA_USE_IPV6_DEFAULT As Boolean = False + Private Const ALPACA_MULTI_THREADED_CHOOSER As String = "Multi Threaded Chooser" : Private Const ALPACA_MULTI_THREADED_CHOOSER_DEFAULT As Boolean = True ' Alpaca integration constants Private Const ALPACA_DYNAMIC_CLIENT_MANAGER_RELATIVE_PATH As String = "ASCOM\Platform 6\Tools\AlpacaDynamicClientManager" @@ -92,6 +90,7 @@ Friend Class ChooserForm Friend AlpacaChooserIncrementalWidth As Integer Friend AlpacaUseIpV4 As Boolean Friend AlpacaUseIpV6 As Boolean + Friend AlpacaMultiThreadedChooser As Boolean ' Delegates Private PopulateDriverComboBoxDelegate As MethodInvoker = AddressOf PopulateDriverComboBox ' Device list combo box delegate @@ -799,6 +798,7 @@ Friend Class ChooserForm AlpacaChooserIncrementalWidth = Convert.ToInt32(registryAccess.GetProfile(CONFIGRATION_SUBKEY, ALPACA_CHOOSER_WIDTH, ALPACA_CHOOSER_WIDTH_DEFAULT.ToString()), CultureInfo.InvariantCulture) AlpacaUseIpV4 = Convert.ToBoolean(registryAccess.GetProfile(CONFIGRATION_SUBKEY, ALPACA_USE_IPV4, ALPACA_USE_IPV4_DEFAULT.ToString()), CultureInfo.InvariantCulture) AlpacaUseIpV6 = Convert.ToBoolean(registryAccess.GetProfile(CONFIGRATION_SUBKEY, ALPACA_USE_IPV6, ALPACA_USE_IPV6_DEFAULT.ToString()), CultureInfo.InvariantCulture) + AlpacaMultiThreadedChooser = Convert.ToBoolean(registryAccess.GetProfile(CONFIGRATION_SUBKEY, ALPACA_MULTI_THREADED_CHOOSER, ALPACA_MULTI_THREADED_CHOOSER_DEFAULT.ToString()), CultureInfo.InvariantCulture) Catch ex As Exception MsgBox("Chooser Read State " & ex.ToString) LogEvent("Chooser Read State ", ex.ToString, System.Diagnostics.EventLogEntryType.Error, EventLogErrors.ChooserFormLoad, ex.ToString) @@ -823,6 +823,7 @@ Friend Class ChooserForm registryAccess.WriteProfile(CONFIGRATION_SUBKEY, ALPACA_CHOOSER_WIDTH, AlpacaChooserIncrementalWidth.ToString(CultureInfo.InvariantCulture)) registryAccess.WriteProfile(CONFIGRATION_SUBKEY, ALPACA_USE_IPV4, AlpacaUseIpV4.ToString(CultureInfo.InvariantCulture)) registryAccess.WriteProfile(CONFIGRATION_SUBKEY, ALPACA_USE_IPV6, AlpacaUseIpV6.ToString(CultureInfo.InvariantCulture)) + registryAccess.WriteProfile(CONFIGRATION_SUBKEY, ALPACA_MULTI_THREADED_CHOOSER, AlpacaMultiThreadedChooser.ToString(CultureInfo.InvariantCulture)) Catch ex As Exception MsgBox("Chooser Write State " & ex.ToString) @@ -907,16 +908,16 @@ Friend Class ChooserForm TL.LogMessage("InitialiseComboBox", $"Arrived at InitialiseComboBox - Running On thread: {Thread.CurrentThread.ManagedThreadId}.") - If DEBUG_SINGLE_THREADING Then - TL.LogMessage("InitialiseComboBox", $"Starting single threaded discovery...") - DiscoverAlpacaDevicesAndPopulateDriverComboBox() - TL.LogMessage("InitialiseComboBox", $"Completed single threaded discovery") - Else ' Normal multi-threading behaviour + If AlpacaMultiThreadedChooser Then ' Multi-threading behaviour where the Chooser UI is displayed immediately while discovery runs in the background TL.LogMessage("InitialiseComboBox", $"Creating discovery thread...") Dim discoveryThread As Thread = New Thread(AddressOf DiscoverAlpacaDevicesAndPopulateDriverComboBox) - TL.LogMessage("InitialiseComboBox", $"Successfully created discovery thread, about to start discovery thread...") + TL.LogMessage("InitialiseComboBox", $"Successfully created discovery thread, about to start discovery on thread {discoveryThread.ManagedThreadId}...") discoveryThread.Start() TL.LogMessage("InitialiseComboBox", $"Discovery thread started OK") + Else ' Single threaded behaviour where the Chooser UI is not displayed until discovery completes + TL.LogMessage("InitialiseComboBox", $"Starting single threaded discovery...") + DiscoverAlpacaDevicesAndPopulateDriverComboBox() + TL.LogMessage("InitialiseComboBox", $"Completed single threaded discovery") End If TL.LogMessage("InitialiseComboBox", $"Exiting InitialiseComboBox on thread: {Thread.CurrentThread.ManagedThreadId}.") diff --git a/Releases/ASCOM 6/Platform/Installer Project/ascom platform 6.mpr b/Releases/ASCOM 6/Platform/Installer Project/ascom platform 6.mpr index 75d8de9f3..6e9151547 100644 --- a/Releases/ASCOM 6/Platform/Installer Project/ascom platform 6.mpr +++ b/Releases/ASCOM 6/Platform/Installer Project/ascom platform 6.mpr @@ -2102,7 +2102,7 @@ ASCOM Platform 6.5 SP1 ASCOM Platform 6.5 SP1 - Installation ASCOM Initiative All rights reserved. http://www.ascom-standards.org -{96FEBA4D-05AD-4875-98B9-FE2104A2B010} +{3B7B6B56-5028-4641-8DF4-4CFCDB362908} ASCOM Initiative ASCOM Initiative https://ascomtalk.groups.io/g/Help