/// <summary> /// 当应用程序开始时创建实行操作的后台工作. /// </summary> protected void Application_Start(object sender, EventArgs e) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new BackgroundWorker.DoWorkEventHandler(worker_DoWork); worker.RunWorker(null); // 后台工作是应用程序级的, // 它将继续工作并被所有用户共享. Application["worker"] = worker; }
/// <summary> /// Create a Background Worker to run the operation /// whenever the application start. /// </summary> protected void Application_Start(object sender, EventArgs e) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new 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; }
/// <summary> /// 当按钮单击时创建一个执行后台工作的操作. /// </summary> protected void btnStart_Click(object sender, EventArgs e) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new BackgroundWorker.DoWorkEventHandler(worker_DoWork); worker.RunWorker(txtParameter.Text); // 这里需要会话模式为"InProc"以保持后台工作运行. Session["worker"] = worker; // 启用定时器更新操作状态. Timer1.Enabled = true; }
/// <summary> /// Create a Background Worker to run the operation when button clicked. /// </summary> protected void btnStart_Click(object sender, EventArgs e) { BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += new BackgroundWorker.DoWorkEventHandler(worker_DoWork); worker.RunWorker(txtParameter.Text); // It needs Session Mode is "InProc" // to keep the Background Worker working. Session["worker"] = worker; // Enable the timer to update the status of the operation. Timer1.Enabled = true; }