Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you can cut and paste, an example is enough.</p> <p>A simple service to periodically log the status of another service. The example does not include the <a href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.aspx" rel="nofollow noreferrer">ServiceInstaller class</a> (to be called by the install utility when installing a service application), so installing is done manually.</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.ServiceProcess; using System.Text; using System.Timers; namespace SrvControl { public partial class Service1 : ServiceBase { Timer mytimer; public Service1() { InitializeComponent(); } protected override void OnStart(string[] args) { if (mytimer == null) mytimer = new Timer(5 * 1000.0); mytimer.Elapsed += new ElapsedEventHandler(mytimer_Elapsed); mytimer.Start(); } void mytimer_Elapsed(object sender, ElapsedEventArgs e) { var srv = new ServiceController("MYSERVICE"); AppLog.Log(string.Format("MYSERVICE Status {0}", srv.Status)); } protected override void OnStop() { mytimer.Stop(); } } public static class AppLog { public static string z = "SrvControl"; static EventLog Logger = null; public static void Log(string message) { if (Logger == null) { if (!(EventLog.SourceExists(z))) EventLog.CreateEventSource(z, "Application"); Logger = new EventLog("Application"); Logger.Source = z; } Logger.WriteEntry(message, EventLogEntryType.Information); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload