static void Main(string[] args)
        {
            var cancelTokenSource = new CancellationTokenSource();

            //MongoDBUtility mdbu = new MongoDBUtility();
            //mdbu.GetEnquiries();

            if (Environment.UserInteractive)
            {
                ProcessStartup processStartup = new ProcessStartup();

                //initialise program
                processStartup.Init(cancelTokenSource);

                //wait
                do
                {
                    if (cancelTokenSource.IsCancellationRequested)
                    {
                        break;
                    }

                    while (!Console.KeyAvailable)
                    {
                        // Do something

                        if (cancelTokenSource.IsCancellationRequested)
                        {
                            break;
                        }
                    }
                } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
            }
            else
            {
                // Run as Windows Service.
                var ServicesToRun = new ServiceBase[]
                {
                    new ServiceController()
                };
                ServiceBase.Run(ServicesToRun);
            }
        }
 protected override void OnStart(string[] args)
 {
     _processStartup = new ProcessStartup(); // Pass the token into the task.
     Task.Run(() => _processStartup.Init(_cancellationTokenSource));
 }