protected override void OnStart(string[] args)
        {
            StopStopping = false;

            // decode the list of printers to stop
            var stopUsString = StopPrintJobs.Properties.Settings.Default.PrintersToStop;
            var stopUs = new List<string>();
            foreach (var printer in stopUsString.Split(';'))
            {
                var trimmedPrinter = printer.Trim();
                if (trimmedPrinter.Length != 0)
                {
                    stopUs.Add(trimmedPrinter);
                }
            }

            if (stopUs.Count == 0)
            {
                TheEventLog.WriteEntry("No printers to stop! Exiting.");
                this.Stop();
                return;
            }

            // prepare for stoppage
            Spool = new Spooler();

            // launch the thread
            StopperThread = new Thread(() => Proc(stopUs));
            StopperThread.Start();
        }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     var allPrinters = Spooler.EnumLocalPrinters(false);
     foreach (var printer in allPrinters)
     {
         Console.WriteLine(printer);
     }
     using (var spooler = new Spooler())
     {
         spooler.PauseNewJobsProc(allPrinters);
     }
 }
 protected override void OnStop()
 {
     StopStopping = true;
     if (Spool != null)
     {
         Spool.StopPausingNewJobs();
     }
     if (StopperThread != null)
     {
         StopperThread.Join();
     }
     if (Spool != null)
     {
         Spool.Dispose();
     }
     Spool = null;
     StopperThread = null;
 }