using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using TeamDev.SDK; using TeamDev.SDK.MVVM; namespace Step.UI { public partial class ServerControlWindow : Form { public ServerControlWindow() { InitializeComponent(); } private static ServerControlWindow ctrlwindow = null; public static void Start() { // Open WinForm Thread th = new Thread(() => { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); ctrlwindow = new ServerControlWindow(); Application.Run(ctrlwindow); }); th.SetApartmentState(ApartmentState.STA); th.Start(); } public static void Stop() { // Close WinForm if (ctrlwindow != null) { ctrlwindow.Invoke((ThreadStart)delegate () { ctrlwindow._closing = true; ctrlwindow.Close(); ctrlwindow = null; }); } } private bool _closing = false; // Avoid closing the window protected override void OnClosing(CancelEventArgs e) { if (!_closing) { e.Cancel = true; this.Hide(); } } private void OpenUiButton_Click(object sender, EventArgs e) { Process.Start("http://localhost:9000/index.html"); } private void StopServerButton_Click(object sender, EventArgs e) { // Send message to listeners and close server MessageServices.Current.Publish("StopServer"); } private void notifyIcon1_Click(object sender, EventArgs e) { this.Show(); } } }