Exemplo n.º 1
0
        /// <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;
        }
Exemplo n.º 2
0
        /// <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;
        }