using System; using System.ServiceProcess; using System.Windows.Forms; namespace Card_Dispenser_Service { static class Program { [STAThread] static void Main() { if (Environment.UserInteractive) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Initialize the service instance Service1 service = new Service1(); service.OnDebug(); // Starts your background thread // Pass the running service instance to Form1 Form1 debugForm = new Form1(service); // Run the Form1 GUI loop Application.Run(debugForm); } else { // Standard production Windows Service execution ServiceBase[] ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); } } } }