I have a method A1 in the class service2021.cs which is not being either called or executed. Can anyone tell me why?
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Diagnostics;
- using System.Linq;
- using System.ServiceProcess;
- using System.Text;
- using System.Threading.Tasks;
- using System.Configuration;
- using System.IO;
- using System.Timers;
- namespace InsertCsvIntoDatabaseTable
- {
- public partial class Service2021 : ServiceBase
- {
- Timer timer = new Timer();
- public Service2021()
- {
- InitializeComponent();
-
- }
- protected override void OnStart(string[] args)
- {
- WriteToFile("Service is started at " + DateTime.Now);
- timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
- WriteToFile("After ElapsedEventHandler in OnStart " + DateTime.Now);
- timer.Interval = 30000;
- WriteToFile("After timer Interval in OnStart " + DateTime.Now);
- timer.Enabled = true;
- WriteToFile("After timer Enabled in OnStart " + DateTime.Now);
- }
- protected override void OnStop()
- {
- WriteToFile("Service is stopped at " + DateTime.Now);
- }
- private void OnElapsedTime(object source, ElapsedEventArgs e)
- {
-
- A1();
- WriteToFile("Service is recall at after A1 method" + DateTime.Now);
- }
- public void WriteToFile(string Message)
- {
- string path = AppDomain.CurrentDomain.BaseDirectory + "\\Logs";
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
- string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\Logs\\ServiceLog_" + DateTime.Now.Date.ToShortDateString().Replace('/', '_') + ".txt";
- if (!File.Exists(filepath))
- {
-
- using (StreamWriter sw = File.CreateText(filepath))
- {
- sw.WriteLine(Message);
- }
- }
- else
- {
- using (StreamWriter sw = File.AppendText(filepath))
- {
- sw.WriteLine(Message);
- }
- }
- }
- public void A1()
- {
- Class2 ob = new Class2();
-
- ob.InsertExcelRecords();
- }
- }
- }