Hi
I am working on windows services. i can bale to run the service for every 1 min. I creating multi thread. but i required the service to run in single thread. can any one please help me to fix my issue.
Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Threading;
namespace SchedulerServiceT
{
public partial class SchedulerService : ServiceBase
{
public SchedulerService()
{
InitializeComponent();
}
TestWriteFile process;
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
base.OnStart(args);
process = new TestWriteFile();
process.StartProcess();
}
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
base.OnStop();
process.StopProcess();
}
public class TestWriteFile
{
public static bool Shutdown = false;
Thread ServiceThread;
public static void WriteCurrentTimewithService()
{
while (Shutdown == false)
{
String str = AppDomain.CurrentDomain.BaseDirectory+"\\run.bat";
Process process = new Process();
process.StartInfo.FileName = str;
process.Start();
//Run this code for every 1 Minutes or stop if service is stoped
Thread.Sleep(60000);
}
}
public void StartProcess()
{
ServiceThread = new Thread(new ThreadStart(WriteCurrentTimewithService));
ServiceThread.Start();
}
public void StopProcess()
{
Shutdown = true;
ServiceThread.Join();
}
}
}
}