Service Issues
I am new to C# programming. I can program Java, but I don't know the studio or its error messages very well.
Here is a code sample from a service tutorial I was trying to build.
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
// Add code here to start your service. This method should set things
// in motion so your service can do its work.
MyTimer.Enabled = True;
}
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
}
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
EventLog Mylog = new EventLog();
/* create an event log */
/* Check if the the Event Log Exists */
/*If MyLog.SourceExists("NewService"){}*/
if (System.Diagnostics.EventLog.Exists("NewService"))
{}else{
MyLog.CreateEventSource("NewService", "NewService_Log");
/* Create Log */
}
MyLog.Source = "NewService" ;
/* Write to the Log */
MyLog.WriteEntry("NewService_Log", "Service is Running" , EventLogEntryType.Information);
}
I get the following error messages:
Error 1 The name 'MyTimer' does not exist in the current context
Error 2 The name 'True' does not exist in the current context
Error 3 The name 'MyLog' does not exist in the current
Error 4 The name 'MyLog' does not exist in the current
Error 5 The name 'MyLog' does not exist in the current
Thanks for the help.
|