-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
64 lines (57 loc) · 1.83 KB
/
Copy pathProgram.cs
File metadata and controls
64 lines (57 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Avalonia;
using System;
using System.IO;
using System.IO.Pipes;
using System.Threading;
namespace TorrentFlow;
internal class Program
{
private static readonly string PipeName = "TorrentFlow_SingleInstance";
[STAThread]
public static void Main(string[] args)
{
bool isFirstInstance;
using (var mutex = new Mutex(true, "TorrentFlow_Mutex", out isFirstInstance))
{
if (!isFirstInstance)
{
if (args.Length > 0)
using (var client = new NamedPipeClientStream(".", PipeName, PipeDirection.Out))
{
client.Connect(500);
using (var writer = new StreamWriter(client))
{
writer.WriteLine(args[0]);
}
}
return;
}
StartPipeServer();
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
}
public static AppBuilder BuildAvaloniaApp()
{
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
private static void StartPipeServer()
{
new Thread(() =>
{
while (true)
using (var server = new NamedPipeServerStream(PipeName, PipeDirection.In))
{
server.WaitForConnection();
using (var reader = new StreamReader(server))
{
var filePath = reader.ReadLine();
if (!string.IsNullOrEmpty(filePath)) App.OnFileOpened(filePath);
}
}
})
{ IsBackground = true }.Start();
}
}