-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplashForm.cs
More file actions
71 lines (63 loc) · 2.79 KB
/
Copy pathSplashForm.cs
File metadata and controls
71 lines (63 loc) · 2.79 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
65
66
67
68
69
70
71
using System.Diagnostics;
using Microsoft.Win32;
namespace MultiDisplayVCPServer
{
public partial class SplashForm : Form
{
public SplashForm()
{
Debug.WriteLine("SplashForm() constructor started.");
InitializeComponent();
Debug.WriteLine("SplashForm() constructor finished.");
// ... (rest of constructor) ...
}
// --- ADD THIS 'LOAD' EVENT HANDLER ---
private void SplashForm_Load(object? sender, EventArgs e)
{
Debug.WriteLine("SplashForm_Load() started.");
// 1. Subscribe to the "server ready" signal
Program.ServerStateChanged += OnServerStateChanged;
Debug.WriteLine("Subscribed to Program.ServerStateChanged.");
// 2. Start the server initialization
Program.StartServerLoop();
Debug.WriteLine("SplashForm_Load() finished, server loop started.");
}
// --- ADD THIS 'SERVER STATE' HANDLER ---
private void OnServerStateChanged(object? sender, int state)
{
Debug.WriteLine($"OnServerStateChanged() called. New state: {state}");
// We only care about the "Running" state
if (state == 1) // State 1 = "Running"
{
Debug.WriteLine("Server state is 1 (Running).");
// Unsubscribe from the event
Program.ServerStateChanged -= OnServerStateChanged;
Debug.WriteLine("Unsubscribed from Program.ServerStateChanged.");
// We need to launch the MainForm on a new UI thread
// to replace this one.
Debug.WriteLine("Creating new UI thread for MainForm.");
var mainThread = new Thread(RunMainForm);
mainThread.SetApartmentState(ApartmentState.STA);
mainThread.Start();
Debug.WriteLine("MainForm thread started.");
// Close this splash screen (on its own UI thread)
Debug.WriteLine("Invoking Close() on SplashForm.");
this.Invoke(() => this.Close());
}
}
// --- ADD THIS HELPER METHOD ---
private void RunMainForm()
{
Debug.WriteLine("RunMainForm() started on new thread.");
// This runs on the new thread, creating a new message loop
// for the main application.
Application.Run(new MainForm());
Debug.WriteLine("RunMainForm() finished (MainForm was closed).");
}
private void lblStatus_Click(object? sender, EventArgs e)
{
// This was empty, but we'll leave it
Debug.WriteLine("lblStatus_Click() called (no action).");
}
}
}