الاثنين، 12 ديسمبر 2011

windows service timer service using background threads


Windows service timer service using background threads

this is a windows service timer which runs in the back ground checking for a event to happen 



using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Diagnostics; 
using System.ServiceProcess; 
using System.Text; 
using System.Threading; 
using System.Configuration; 
using System.Data.SqlClient; 
using System.Net; 
using System.Net.Mail; 
namespace servicename 
{ 
public partial class servicename : ServiceBase 
{ 
public servicename() 
{ 
InitializeComponent(); 
this.ServiceName = ""; 
this.CanStop = true; 
this.CanPauseAndContinue = false; 
this.AutoLog = true; 
} 


private TimerState s = new TimerState(); 
int PollInterval = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PollMinutes"]); 

protected override void OnStart(string[] args) 
{ 

} 

protected override void OnStop() 
{ 
s.tmr.Dispose(); 
s.tmr = null; 
} 



private void QueryForLatestUpdates() 
{ 


} 


public void Tmr_Elapsed(object state) 
{ 
QueryForLatestUpdates(); 
} 


public class TimerState 
{ 
public int counter = 0; 
public Timer tmr; 
} 
} 
} 


///add this designer.cs 
private void InitializeComponent() 
{ 
components = new System.ComponentModel.Container(); 
this.ServiceName = "CallSourceWinService"; 
Timer Tmr = new Timer(new TimerCallback(Tmr_Elapsed), null, 0, PollInterval); 
s.tmr = Tmr; 
}

ليست هناك تعليقات:

إرسال تعليق