我使用sqldependency和signalR AND线程,但它继续无限循环

时间:2015-08-01 12:46:52

标签: multithreading loops signalr infinite sqldependency

我使用sqldependency和signalR AND线程,但它继续无限循环 在global.aspx和sqldependency以及signalR中组合BackgroundWorker 我不知道问题请帮助我。

class Article
  # let's say that model has 'source' attributes with Markdown
  # and we want to put resulting HTML into 'html' attribute
  before_save :markdown

  def markdown
    self.html = Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(source)
  end
end

string user_id;

void Application_Start(object sender, EventArgs e)
{
    //var session = HttpContext.Current.Session;
    //if (session != null && HttpContext.Current != null)
    //{
    try
    {
        CSASPNETBackgroundWorker.BackgroundWorker worker = new CSASPNETBackgroundWorker.BackgroundWorker();
        worker.DoWork += new CSASPNETBackgroundWorker.BackgroundWorker.DoWorkEventHandler(worker_DoWork);
        worker.RunWorker(null);

        // This Background Worker is Applicatoin Level,
        // so it will keep working and it is shared by all users.
        Application["worker"] = worker;
        // Code that runs on application startup 
    }
    catch { }
    // }
    System.Data.SqlClient.SqlDependency.Start(connectionstring);
}

公共类AlarmInfoRepository {      string connectionstr = ConfigurationManager.ConnectionStrings [" officeConnectionString"]。ConnectionString;      public IEnumerable GetData(string user_id)      {

void worker_DoWork(ref int progress,
      ref object _result, params object[] arguments)
{
    // Do the operation every 1 second wihout the end.
    while (true)
    {
        Random rand = new Random();
        int randnum = rand.Next(5000, 20000);
        Thread.Sleep(randnum);
        // This statement will run every 1 second.
       // string user_id = "";
       // if (HttpContext.Current != null && HttpContext.Current.Session != null)
        {
           // user_id = "22";// HttpContext.Current.Session["userId"].ToString();
            user_id = ConfigurationManager.AppSettings["session_user_id"].ToString();
            updatealarm(user_id);
        }
        // Other logic which you want it to keep running.
        // You can do some scheduled tasks here by checking DateTime.Now.
    }
}

}

0 个答案:

没有答案