+1
-1
@@ -1 +1 @@
|
|||||||
1.0.20
|
1.0.21
|
||||||
|
|||||||
@@ -6,10 +6,10 @@
|
|||||||
<LangVersion>7.3</LangVersion>
|
<LangVersion>7.3</LangVersion>
|
||||||
<RootNamespace>MonsterMonitor</RootNamespace>
|
<RootNamespace>MonsterMonitor</RootNamespace>
|
||||||
<AssemblyName>devenv</AssemblyName>
|
<AssemblyName>devenv</AssemblyName>
|
||||||
<AssemblyVersion>1.0.20</AssemblyVersion>
|
<AssemblyVersion>1.0.21</AssemblyVersion>
|
||||||
<Version>1.0.20</Version>
|
<Version>1.0.21</Version>
|
||||||
<FileVersion>1.0.20</FileVersion>
|
<FileVersion>1.0.21</FileVersion>
|
||||||
<InformationalVersion>1.0.20</InformationalVersion>
|
<InformationalVersion>1.0.21</InformationalVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
<PackageReference Include="Costura.Fody" Version="6.0.0">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using MonsterMonitor.UI;
|
using MonsterMonitor.UI;
|
||||||
|
|
||||||
@@ -6,9 +7,21 @@ namespace MonsterMonitor
|
|||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
|
private const string SingleInstanceMutexName = @"Global\MonsterMonitor_v2_SingleInstance";
|
||||||
|
private const string ActivateEventName = @"Global\MonsterMonitor_v2_Activate";
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
private static void Main()
|
private static void Main()
|
||||||
{
|
{
|
||||||
|
var createdNew = false;
|
||||||
|
using (var mutex = new Mutex(true, SingleInstanceMutexName, out createdNew))
|
||||||
|
{
|
||||||
|
if (!createdNew)
|
||||||
|
{
|
||||||
|
TrySignalExistingInstance();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Application.ThreadException += (sender, args) =>
|
Application.ThreadException += (sender, args) =>
|
||||||
{
|
{
|
||||||
MessageBox.Show(
|
MessageBox.Show(
|
||||||
@@ -29,7 +42,38 @@ namespace MonsterMonitor
|
|||||||
|
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new MainForm());
|
using (var activateEvent = new EventWaitHandle(false, EventResetMode.AutoReset, ActivateEventName))
|
||||||
|
{
|
||||||
|
var form = new MainForm();
|
||||||
|
ThreadPool.RegisterWaitForSingleObject(
|
||||||
|
activateEvent,
|
||||||
|
(state, timedOut) =>
|
||||||
|
{
|
||||||
|
var mainForm = state as MainForm;
|
||||||
|
mainForm?.RestoreAndActivateFromExternalSignal();
|
||||||
|
},
|
||||||
|
form,
|
||||||
|
Timeout.Infinite,
|
||||||
|
false);
|
||||||
|
|
||||||
|
Application.Run(form);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TrySignalExistingInstance()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var activateEvent = EventWaitHandle.OpenExisting(ActivateEventName))
|
||||||
|
{
|
||||||
|
activateEvent.Set();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Если не удалось отправить сигнал, просто завершаем второй инстанс.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,6 +135,33 @@ namespace MonsterMonitor.UI
|
|||||||
Activate();
|
Activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RestoreAndActivateFromExternalSignal()
|
||||||
|
{
|
||||||
|
if (InvokeRequired)
|
||||||
|
{
|
||||||
|
BeginInvoke(new Action(RestoreAndActivateFromExternalSignal));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_log.Info("Получен сигнал активации от второго инстанса.");
|
||||||
|
|
||||||
|
if (!Visible)
|
||||||
|
{
|
||||||
|
Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WindowState == FormWindowState.Minimized)
|
||||||
|
{
|
||||||
|
WindowState = FormWindowState.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Небольшой трюк для надежного вывода окна на передний план.
|
||||||
|
TopMost = true;
|
||||||
|
Activate();
|
||||||
|
TopMost = false;
|
||||||
|
Focus();
|
||||||
|
}
|
||||||
|
|
||||||
private void ExitApplication()
|
private void ExitApplication()
|
||||||
{
|
{
|
||||||
_allowClose = true;
|
_allowClose = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user