繁体   English   中英

如何在使用ASP.NET构建的Web服务中安排方法调用

[英]How to schedule method calls in a webservice built with ASP.NET

我使用HttpHandler构建了一个RESTful Web服务来访问MSSQL数据库,我需要计划将由用户操作触发的方法调用,即,一个用户在下周的17PM安排一个事件,因此将在以下时间触发负责发送通知的方法那时。 我使用System.Threading.Timer尝试了以下代码,但是没有用

ServiceAPI s = new ServiceAPI();
//s.CreatePreferences(true, true, true, 3);
TimeSpan alertTime = new TimeSpan(17, 30, 00);
DateTime current = DateTime.Now;
TimeSpan timeToGo = new TimeSpan(00, 01, 00);//alertTime - current.TimeOfDay;
if(timeToGo < TimeSpan.Zero)
{
       return; // time already passed
}
System.Threading.Timer timer = new System.Threading.Timer(x =>
{
       s.SendNotification(true, true, true, 10);
}, null, timeToGo, System.Threading.Timeout.InfiniteTimeSpan);

PS我的Web服务托管在IIS服务器中。

您无法从webservice项目中执行此操作,您需要一个客户端,该客户端将根据一些预定义的时间表调用您的webservice方法,您是否正在使用Windows Azure? (如果有的话,这里有一个调度程序功能: https : //azure.microsoft.com/ro-ro/services/scheduler/ )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM