日期:2014-05-18 浏览次数:20661 次
using System;
using System.Threading;
public class Example
{
private static Timer ticker;
public static void TimerMethod(Object state)
{
Console.Write(".");
}
public static void Main()
{
ticker = new Timer(TimerMethod, null, 1000, 1000);
Console.WriteLine("Press the Enter key to end the program.");
Console.ReadLine();
}
}
------解决方案--------------------
你要的是服务器端的Timer. 只要第一个访问者的第一次请求 (Application_Start 事件)即可启动Timer.
public class Global_asax : System.Web.HttpApplication
{
private static TokenUpdateAgent _token_update_agent = new TokenUpdateAgent();
void Application_Start(object sender, EventArgs e)
{
int module_id = App.Shared.Constants.GetPluginID;
MIA.MVP.HQ.Framework.Security.HQUserGroupModuleSecurityCache.GetModuleSecuirty(module_id);
_token_update_agent.Initialize();
}
}
------解决方案--------------------
在Web中使用定时器,大多要考虑ajax应用