Skip to content

Commit a032006

Browse files
committed
allow only one instance of app to be running
1 parent 06884c8 commit a032006

5 files changed

Lines changed: 24 additions & 41 deletions

File tree

GUI/AboutBox.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GUI/SensorNotifyIcon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ private string GetString() {
194194
case SensorType.Level:
195195
return string.Format("{0:F0}", sensor.Value);
196196
case SensorType.Power:
197-
return string.Format("{0:N1}", sensor.Value);
197+
return string.Format(sensor.Value < 10 ? "{0:N1}" : "{0:F0}", sensor.Value);
198198
case SensorType.Data:
199199
return string.Format("{0:F0}", sensor.Value);
200200
case SensorType.Factor:

OpenHardwareMonitor.csproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,8 @@
396396
<EmbeddedResource Include="Resources\nvidia.png" />
397397
</ItemGroup>
398398
<ItemGroup>
399-
<Content Include="Controls\Resources\minus.bmp" />
400-
<Content Include="Controls\Resources\plus.bmp" />
401-
<Content Include="Controls\Resources\uncheck.bmp" />
402-
<Content Include="Controls\Resources\unknown.bmp" />
403399
<EmbeddedResource Include="Hardware\WinRing0.sys" />
404400
<EmbeddedResource Include="Hardware\WinRing0x64.sys" />
405-
<Content Include="Controls\Resources\loading_icon" />
406401
<None Include="Controls\.editorconfig" />
407402
<None Include="Controls\Tree\ClassDiagram.cd" />
408403
<None Include="Controls\Tree\NodeControls\ClassDiagram.cd" />
@@ -519,13 +514,6 @@
519514
<ItemGroup>
520515
<EmbeddedResource Include="Resources\throughput.png" />
521516
</ItemGroup>
522-
<ItemGroup>
523-
<Content Include="Controls\Resources\check.bmp" />
524-
<Content Include="Controls\Resources\DVSplit.cur" />
525-
<Content Include="Controls\Resources\Folder.bmp" />
526-
<Content Include="Controls\Resources\FolderClosed.bmp" />
527-
<Content Include="Controls\Resources\Leaf.bmp" />
528-
</ItemGroup>
529517
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
530518
<ProjectExtensions>
531519
<VisualStudio AllowExistingFolder="true" />

Program.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,35 @@ This Source Code Form is subject to the terms of the Mozilla Public
1919
namespace OpenHardwareMonitor {
2020
public static class Program {
2121

22+
static Mutex mutex = new Mutex(true, "{3661aef2-95dc-433e-932c-2e06112d24ec}");
23+
2224
[STAThread]
2325
public static void Main() {
24-
#if !DEBUG
25-
Application.ThreadException +=
26-
new ThreadExceptionEventHandler(Application_ThreadException);
27-
Application.SetUnhandledExceptionMode(
28-
UnhandledExceptionMode.CatchException);
29-
30-
AppDomain.CurrentDomain.UnhandledException +=
31-
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
32-
#endif
3326

3427
if (!IsNetFramework45Installed())
3528
Environment.Exit(0);
3629

30+
if (!mutex.WaitOne(TimeSpan.Zero, true)) {
31+
MessageBox.Show("Another instance of the application is already running.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
32+
Environment.Exit(0);
33+
}
34+
35+
#if !DEBUG
36+
Application.ThreadException +=
37+
new ThreadExceptionEventHandler(Application_ThreadException);
38+
Application.SetUnhandledExceptionMode(
39+
UnhandledExceptionMode.CatchException);
40+
41+
AppDomain.CurrentDomain.UnhandledException +=
42+
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
43+
#endif
44+
3745
Application.EnableVisualStyles();
3846
Application.SetCompatibleTextRenderingDefault(false);
39-
using (GUI.MainForm form = new GUI.MainForm()) {
40-
form.FormClosed += delegate(Object sender, FormClosedEventArgs e) {
41-
Application.Exit();
42-
};
47+
using (var form = new MainForm()) {
48+
form.FormClosed += (sender, e) => Application.Exit();
4349
Application.Run();
50+
mutex.ReleaseMutex();
4451
}
4552
}
4653

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
1-
/*
2-
3-
This Source Code Form is subject to the terms of the Mozilla Public
4-
License, v. 2.0. If a copy of the MPL was not distributed with this
5-
file, You can obtain one at http://mozilla.org/MPL/2.0/.
6-
7-
Copyright (C) 2009-2020 Michael Möller <mmoeller@openhardwaremonitor.org>
8-
9-
*/
10-
11-
using System;
12-
using System.Reflection;
13-
using System.Runtime.CompilerServices;
1+
using System.Reflection;
142
using System.Runtime.InteropServices;
153

164
[assembly: AssemblyTitle("Open Hardware Monitor")]
175
[assembly: AssemblyDescription("")]
186
[assembly: AssemblyConfiguration("")]
197
[assembly: AssemblyCompany("")]
208
[assembly: AssemblyProduct("Open Hardware Monitor")]
21-
[assembly: AssemblyCopyright("Copyright © 2009-2020 Michael Möller")]
9+
[assembly: AssemblyCopyright("Copyright © 2009-2022 Sergiy Egoshyn")]
2210
[assembly: AssemblyTrademark("")]
2311
[assembly: AssemblyCulture("")]
2412

0 commit comments

Comments
 (0)