Skip to content

Commit 3aa540e

Browse files
committed
fixed a bug with the request (for no internet connection)
1 parent 5d8995b commit 3aa540e

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

src/MainWindow.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics;
55
using System.Globalization;
66
using System.Net.Http.Headers;
7+
using System.Net.Sockets;
78
using System.Reflection;
89
using System.Runtime.InteropServices;
910
using System.Text;
@@ -38,7 +39,7 @@ public partial class MainWindow : Form
3839
private uint NtActualResolution = 0;
3940

4041
private readonly static bool emptyBuildVersion = Assembly.GetEntryAssembly().GetName().Version.Build == -1;
41-
private readonly string ProgramVersion = emptyBuildVersion ? Assembly.GetEntryAssembly().GetName().Version.Build.ToString() : "1.0.3.8";
42+
private readonly string ProgramVersion = emptyBuildVersion ? Assembly.GetEntryAssembly().GetName().Version.Build.ToString() : "1.0.3.9";
4243

4344
private static Dictionary<string, int> Logger = new();
4445

@@ -129,21 +130,44 @@ public MainWindow()
129130

130131
public string GetRequest(string uri, bool jsonaccept)
131132
{
132-
HttpClient client = new HttpClient();
133-
client.BaseAddress = new Uri(uri);
133+
HttpClient client = new();
134+
client.BaseAddress = new(uri);
135+
client.Timeout = new(0, 0, 4);
134136

135137
if (jsonaccept)
136138
client.DefaultRequestHeaders
137139
.Accept
138140
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
139141

140-
var res = client.GetStringAsync(uri).Result;
142+
string res = string.Empty;
143+
144+
try
145+
{
146+
res = client.GetStringAsync(uri).Result;
147+
}
148+
catch (AggregateException ex)
149+
{
150+
ex.Handle(x =>
151+
{
152+
if (x is HttpRequestException || x is SocketException)
153+
{
154+
return true;
155+
}
156+
157+
return false;
158+
});
159+
}
160+
141161
return res;
142162
}
143163

144164
public void CheckForUpdates()
145165
{
146166
string json = GetRequest("https://github.com/TorniX0/OpenTimerResolution/releases/latest", true);
167+
168+
if (json == string.Empty)
169+
return;
170+
147171
var obj = JObject.Parse(json);
148172
string ver = obj["tag_name"].ToString();
149173
ver = ver.Substring(8, ver.Length - 8);
@@ -218,7 +242,7 @@ private void stopButton_Click(object sender, EventArgs e)
218242
return;
219243

220244
var result = NtSetTimerResolution((int)(float.Parse(timerResolutionBox.Text) * 10000f), false, out NtCurrentResolution);
221-
245+
222246
if (result != NtStatus.Success)
223247
{
224248
MessageBox.Show($"Error code: {result}", "OpenTimerResolution", MessageBoxButtons.OK, MessageBoxIcon.Error);
@@ -265,7 +289,7 @@ private void minimizeIcon_MouseClick(object sender, MouseEventArgs e)
265289
this.ShowInTaskbar = true;
266290
this.Show();
267291
this.BringToFront();
268-
this.WindowState = FormWindowState.Normal;
292+
this.WindowState = FormWindowState.Normal;
269293
}
270294

271295
private void quitStripMenu_Click(object sender, EventArgs e)
@@ -475,4 +499,4 @@ private void updateConfigButton_Click(object sender, EventArgs e)
475499

476500
#endregion
477501
}
478-
}
502+
}

src/OpenTimerResolution.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<StartupObject>OpenTimerResolution.Program</StartupObject>
99
<ApplicationIcon>program.ico</ApplicationIcon>
1010
<ApplicationManifest>app.manifest</ApplicationManifest>
11-
<AssemblyVersion>1.0.3.8</AssemblyVersion>
12-
<FileVersion>1.0.3.8</FileVersion>
13-
<Version>1.0.3.8</Version>
11+
<AssemblyVersion>1.0.3.9</AssemblyVersion>
12+
<FileVersion>1.0.3.9</FileVersion>
13+
<Version>1.0.3.9</Version>
1414
<DebugType>embedded</DebugType>
1515
<Product>OpenTimerResolution</Product>
1616
<Description>OpenTimerResolution is a lightweight open-source application that changes the resolution of the Windows system Timer to a specified value and has a memory cache cleaner included.</Description>

src/Properties/PublishProfiles/FolderProfile.pubxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
1010
<PublishProtocol>FileSystem</PublishProtocol>
1111
<TargetFramework>net6.0-windows</TargetFramework>
1212
<SelfContained>False</SelfContained>
13-
<IncludeAllContentForSelfExtract>False</IncludeAllContentForSelfExtract>
13+
<IncludeAllContentForSelfExtract>True</IncludeAllContentForSelfExtract>
1414
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
1515
<PublishSingleFile>True</PublishSingleFile>
1616
<PublishReadyToRun>False</PublishReadyToRun>
1717
</PropertyGroup>
18-
</Project>
18+
</Project>

0 commit comments

Comments
 (0)