Windows 서비스가 있습니다. 이 서비스는 Active Directory에서 사용자 데이터를 가져온 다음 xml 파일을 로컬 시스템에 저장합니다. 이 서비스는 타이머를 사용하여 매 10 분마다 작동합니다. 처음 실행하면 85MB의 메모리를 사용하고 10 분 후에는 118MB를 소비하는 등의 작업을 수행합니다. 실행될 때마다 여분의 메모리가 필요합니다.Windows 서비스, 메모리가 Active Directory에서 데이터를 가져올 때마다 증가합니다.
누군가 나를 이해하는 데 도움이 될 수 있습니까?
protected override void OnStart(string[] args)
{
StartProcess();
}
private void StartProcess()
{
sEvent = "AD XML Generator Started at " + System.DateTime.Now.ToString();
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
EventLog.WriteEntry(sSource, sEvent);
ActiveDirectoryGenericFunctions obj = new ActiveDirectoryGenericFunctions();
obj.GenerateXMLFileForAllUsers(DomainA, DomainB, xmlFileName);
RunService();
//this.Stop();
}
protected override void OnStop()
{
//Write to Event Log - Stop of Service also written to Evenbt automatically
sEvent = "AD XML Generator Stopped at " + System.DateTime.Now.ToString();
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
EventLog.WriteEntry(sSource, sEvent);
}
private void RunService()
{
_timer = new Timer();
_timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
_timer.AutoReset = true; // AutoReset = true means after specified interval the timer'll automatically be restarted
_timer.Interval = Convert.ToDouble(ConfigurationManager.AppSettings["ServiceHour"].ToString());// 300000; //5minutes// (0.1*60*60*1000); // specify some interval here in milliseconds e.g. 4 hours (4*60*60*1000)
_timer.Start();
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
RunService();
StartProcess();
}
에 한 번 초기화하는 방법이다? –
Elapsed 핸들러가 트리거 될 때마다 Timer 오브젝트를 작성 중입니다. OnStart에서 타이머를 한 번만 만듭니다. –