1 instance only
This commit is contained in:
parent
99b662bfec
commit
37d1cb7d70
15
Program.cs
15
Program.cs
@ -10,6 +10,8 @@ using Discord.WebSocket;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace silverworker_discord
|
namespace silverworker_discord
|
||||||
{
|
{
|
||||||
@ -31,6 +33,18 @@ namespace silverworker_discord
|
|||||||
}
|
}
|
||||||
public async Task MainAsync()
|
public async Task MainAsync()
|
||||||
{
|
{
|
||||||
|
Process[] processes = Process.GetProcesses();
|
||||||
|
Process currentProc = Process.GetCurrentProcess();
|
||||||
|
Console.WriteLine("Current proccess: {0}", currentProc.ProcessName);
|
||||||
|
foreach (Process process in processes)
|
||||||
|
{
|
||||||
|
if (currentProc.ProcessName == process.ProcessName && currentProc.Id != process.Id)
|
||||||
|
{
|
||||||
|
Console.Error.WriteLine($"Another instance of this process is already running: {process.Id}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_client = new DiscordSocketClient();
|
_client = new DiscordSocketClient();
|
||||||
|
|
||||||
_client.Log += Log;
|
_client.Log += Log;
|
||||||
@ -47,6 +61,7 @@ namespace silverworker_discord
|
|||||||
});
|
});
|
||||||
// Block this task until the program is closed.
|
// Block this task until the program is closed.
|
||||||
await Task.Delay(-1);
|
await Task.Delay(-1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable 4014 //the "you're not awaiting this" warning. yeah I know, that's the beauty of an async method lol
|
#pragma warning disable 4014 //the "you're not awaiting this" warning. yeah I know, that's the beauty of an async method lol
|
||||||
|
Reference in New Issue
Block a user