0
我使用HttpHandler构建了一个RESTful web服务来访问MSSQL数据库,我需要调度将由用户操作触发的方法调用,即用户在下一个时间安排事件一周17点,所以负责发送通知的方法将在当时被解雇。我尝试使用System.Threading.Timer下面的代码,但它没有工作如何在使用ASP.NET构建的web服务中调度方法调用
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);
P.S.我的web服务托管在IIS服务器中。
不幸的是,它被托管在一个名为somee的免费托管服务中。除了从客户端触发它之外,没有其他办法可以做到吗?我的客户端平台在Android上,我正在使用Google的Firebase云消息传递进行定期通知,但是我需要在计划事件的情况下编写推送通知,因此它必须从服务器端触发,不要哟? – AymanKun