Skip to content

Commit 7377563

Browse files
committed
Run Win32 API asynchronously
1 parent f179325 commit 7377563

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,13 +1426,30 @@ private async void ValidateAndApplyDnsSettings(object sender, RoutedEventArgs e)
14261426
string? dnsHost = _dnsSettingsContext.ExternalDnsAddresses;
14271427
DnsConnectionType connType = (DnsConnectionType)_dnsSettingsContext.ExternalDnsConnectionType;
14281428
string dnsSettings = $"{dnsHost}|{connType}";
1429-
if (!HttpClientBuilder.TryParseDnsHosts(dnsSettings, true, true, out string[]? resultHosts))
1429+
1430+
(bool isSuccess, string[]? resultHosts) resultHosts = await Task.Factory.StartNew(() =>
1431+
{
1432+
bool isSuccess =
1433+
HttpClientBuilder.TryParseDnsHosts(dnsSettings, true, true,
1434+
out string[]? resultHosts);
1435+
return (isSuccess, resultHosts);
1436+
}, TaskCreationOptions.DenyChildAttach);
1437+
1438+
if (!resultHosts.isSuccess)
14301439
{
14311440
throw new InvalidOperationException($"The current DNS host string: {dnsSettings} has malformed separator or one of the hostname's IPv4/IPv6 cannot be resolved! " +
14321441
$"Also, make sure that you use one of these separators: {_dnsSettingsSeparatorList}");
14331442
}
14341443

1435-
if (!HttpClientBuilder.TryParseDnsConnectionType(dnsSettings, out DnsConnectionType resultConnType))
1444+
1445+
(bool isSuccess, DnsConnectionType resultConnType) resultConnType = await Task.Factory.StartNew(() =>
1446+
{
1447+
bool isSuccess =
1448+
HttpClientBuilder.TryParseDnsConnectionType(dnsSettings, out DnsConnectionType resultConnType);
1449+
return (isSuccess, resultConnType);
1450+
}, TaskCreationOptions.DenyChildAttach);
1451+
1452+
if (!resultConnType.isSuccess)
14361453
{
14371454
DnsConnectionType[] types = Enum.GetValues<DnsConnectionType>();
14381455
string typesInList = string.Join(", ", types);
@@ -1444,7 +1461,7 @@ private async void ValidateAndApplyDnsSettings(object sender, RoutedEventArgs e)
14441461

14451462
HttpClient httpClientWithCustomDns = new HttpClientBuilder<SocketsHttpHandler>()
14461463
.UseLauncherConfig(skipDnsInit: true)
1447-
.UseExternalDns(resultHosts, resultConnType)
1464+
.UseExternalDns(resultHosts.resultHosts, resultConnType.resultConnType)
14481465
.Create();
14491466
HttpResponseMessage responseMessage =
14501467
await

0 commit comments

Comments
 (0)