Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 运行一个方法并进入WebApp的生存期_C#_Asp.net_Lifetime - Fatal编程技术网

C# 运行一个方法并进入WebApp的生存期

C# 运行一个方法并进入WebApp的生存期,c#,asp.net,lifetime,C#,Asp.net,Lifetime,有一个应用程序可以从新闻机构的rss中收集新闻,可能像Google Reader!。 我想调用一个方法在一段时间内更新我在DB中的链接,它将持续到应用程序的生命周期。 像钟一样的东西!!! 毫不犹豫 我知道一些关于线程的信息 但问题是: 在哪里可以调用我的更新方法 我有一些类,其中一些类是从其他类派生的,我使用它们在我的项目中分层 我调用Global.asax中的方法: protected void Application_Start(object sender, EventArgs e) {

有一个应用程序可以从新闻机构的rss中收集新闻,可能像Google Reader!。 我想调用一个方法在一段时间内更新我在DB中的链接,它将持续到应用程序的生命周期。 像钟一样的东西!!! 毫不犹豫

我知道一些关于线程的信息 但问题是:

在哪里可以调用我的更新方法

我有一些类,其中一些类是从其他类派生的,我使用它们在我的项目中分层

我调用Global.asax中的方法:

protected void Application_Start(object sender, EventArgs e)
{
    Thread thread = new Thread(new ThreadStart(UpdateRss));
    thread.Start();
    Thread.Sleep(1000);
}

public void UpdateRss()
{
    while (true)
    {

        using (LinkService linkSrv = new LinkService())
        {
            linkSrv.UpdateLinksFromRSS();
        }
    }
}
LinkService中UpdateLinkFromRSS的定义是:

 public void UpdateLinksFromRSS()
{
    List<RssInfo> q;
    using (RssService RssSrv = new RssService())
    {
        q = RssSrv.GetRssInfoes();
    }
    foreach (var item in q)
    {
        AddLink(item);
    }
}
当我运行项目时!
我从这行得到一个错误:返回HttpContext.Current.Cache

这个BaseService是什么?您得到的确切错误是什么?BaseService是:包含该属性的公共抽象类BaseService:IDisposable{},我的错误是:“对象引用未设置为对象的实例。”从该属性中,您是否尝试过通过HttpRuntime.cache访问ASP.NET缓存?tnx 4 ur响应如何使用HttpRuntime.cache??
 public static System.Web.Caching.Cache Cache
        {
            get { return HttpContext.Current.Cache; }
        }