Windows服务查询 [英] Windows Service Query

查看:79
本文介绍了Windows服务查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

全部

我在Windows服务中有问题.我在Windows服务中调用一个Web服务及其参考.这里为每分钟运行Windows服务放置了一个计时器方法.这里面临一个问题,一旦启动Windows服务,假设WebService方法需要在一个表中插入10000条记录,那么那时将花费超过一分钟的时间.但是这里我们给了1分钟时间来运行Windows服务,该Windows服务每分钟运行一次.因此,最后将要限制此限制,因此一旦调用了该服务的WebService方法完成,然后运行Windows Service.我的意思是WebService处于运行状态,无需每分钟运行Windows即可完成WebService任务.

请参见Windows服务的以下代码:

Dear,

All

I have some problem in Windows Service. Am calling one Webservice in Windows Service with their reference. Here am putting a timer method for to run the Windows Service for every minute. Here am facing a problem, once start the Windows service, for suppose in that WebService method need to insert 10000 records in a table, So at that time it will take more than minute. But here we give 1 minute to run Windows service, this windows service runs every minute. So finally am going to restrict this, so once WebService method called upto that service complete, then Run the Windows Service. I mean that WebService is in running state, no need to run the Windows for every minute upto complete the WebService task.

See below code of Windows Service:

namespace WinVJService
{
partial class WinVJService : ServiceBase
{
protected System.Timers.Timer timer;

public WinVJService()
{
InitializeComponent();
}

protected void InitializeTimer()
{
if (timer == null)
{
timer = new System.Timers.Timer();
timer.AutoReset = true;
timer.Interval = ReadAppSettingInterval();
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
}
}

private void timer_Elapsed(object source, System.Timers.ElapsedEventArgs e)
{
RunCommands();
}

protected void RunCommands()
{

RefVJService.VJServiceSoapClient objJob = new RefVJService.VJServiceSoapClient(); // WebService Reference Object
objJob.RunJob();                                         // Here calling Web Service method


EventLog.WriteEntry(ServiceName + "VJ Service ran ok");
}

protected double ReadAppSettingInterval()
{
double interval = 60000, tempInterval; //initialize to ten minutes.
if (ConfigurationSettings.AppSettings != null &&
ConfigurationSettings.AppSettings["IntervalMinutes"] != null)
{
string intervalMin;
intervalMin = ConfigurationSettings.AppSettings["IntervalMinutes"];
if (Double.TryParse(intervalMin, NumberStyles.Any,
NumberFormatInfo.InvariantInfo, out tempInterval))
interval = tempInterval * 60000;
}
return interval;
}

protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
EventLog.WriteEntry(ServiceName + "VJ Service started");
InitializeTimer();
timer.Enabled = true;
}

protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
EventLog.WriteEntry(ServiceName + "VJ Service stopped");
timer.Enabled = false;
}
}
}

推荐答案

朋友们...我从Google那里得到了解决方案.

这可能会对其他遭受此问题困扰的人有所帮助.

受保护的void RunCommands()
{
timer.Enabled = false; //禁用操作开始之前的时间
RefVJService.VJServiceSoapClient objJob =新的RefVJService.VJServiceSoapClient(); //WebService参考对象
objJob.RunJob(); //这里调用Web Service方法
EventLog.WriteEntry(ServiceName +"VJ服务运行正常");
timer.Enabled = true; //操作完成后启用时间
}



谢谢与问候,
Vinod Bheemisetty.
Hi Friends... I got the solution from google.

This may helpful to some other people those suffering with this problem.

protected void RunCommands()
{
timer.Enabled=false; // disable time before the operation starts
RefVJService.VJServiceSoapClient objJob = new RefVJService.VJServiceSoapClient(); // WebService Reference Object
objJob.RunJob(); // Here calling Web Service method
EventLog.WriteEntry(ServiceName + "VJ Service ran ok");
timer.Enabled=true; // enable time once the operation completed
}



Thanks & Regards,
Vinod Bheemisetty.


这篇关于Windows服务查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆