1,978
社区成员
发帖
与我相关
我的任务
分享
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
Application.Add("gtest", 0); //这个是我定义的全局变量
acc_TokenClass mythread = new acc_TokenClass();
mythread.start();
}
namespace HTMLTest.myThread
{
public class acc_TokenClass
{
BaseDao basedao = new BaseDao();
Thread thread = null;
public bool isOpen = false
public void run()
{
while (true)
{
if (thread != null)
{
HttpContext.Current.Application["gtest"] = 5;
}
Thread.Sleep(60000 * 90);
}
}
public void start()
{
if (thread == null)
{
thread = new Thread(run);
isOpen = true;
thread.Start();
}
}
}
}
protected void Application_Start()
{
.....
acc_TokenClass mythread = new acc_TokenClass();
mythread.context = HttpContext.Current; //这里把当前的current赋值过去
mythread.start();
}
namespace HTMLTest.myThread
{
public class acc_TokenClass
{
BaseDao basedao = new BaseDao();
Thread thread = null;
public bool isOpen = false
public HttpContext context; //这里在类里面定义一个变量
public void run()
{
while (true)
{
if (thread != null)
{
context.Application["gtest"] = 5; //这里直接调用赋值即可,我试了试可行的
}
Thread.Sleep(60000 * 90);
}
}
public void start()
{
if (thread == null)
{
thread = new Thread(run);
isOpen = true;
thread.Start();
}
}
}
}