如何使用IHTTPAsyncHandler?

发布于 2024-07-12 13:02:01 字数 166 浏览 3 评论 0原文

想象一下,我有一些代码需要从文件的开头到结尾读取,如下所示:

while(sw.readline != null)
{

}

我希望这是完全异步的。 当从 IHTTPAsyncHandler 派生时,这段代码会去哪里?获取每行内容的代码会去哪里?

Imagine I have some code to read from the start to end of a file like so:

while(sw.readline != null)
{

}

I want this to be fully asynchronous. When deriving from IHTTPAsyncHandler, where would this code go and where would would the code to get the content of each line go?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燃情 2024-07-19 13:02:01

我最近向 ASP.NET 页面添加了一些异步进程,以便在用户等待结果时允许一些长时间运行的进程发生。 我发现 IHTTPAsyncHandler 相当不够。 它所做的只是允许您在页面开始处理时分离一个新线程。 您仍然需要创建自己的线程并创建 AsyncRequestResult。

相反,我最终只是在代码隐藏中使用普通线程,更加简洁:

using System;
using System.Web;
using System.Threading;

namespace Temp {
    public partial class thread : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            Thread thread = new Thread(new ThreadStart(myAsyncProcess));
            thread.Start();
        }

        private void myAsyncProcess() {
            // Long running process
        }
    }
}

I recently added some asynchronous processes to my ASP.NET pages in order to allow some long-running processes to take place while the user waited for the results. I found the IHTTPAsyncHandler quite inadequate. All it does is allow you to spin off a new thread while the page begins processing. You still have to make your own thread and create a AsyncRequestResult.

Instead I ended up just using a normal thread in my codebehind instead, much more succinct:

using System;
using System.Web;
using System.Threading;

namespace Temp {
    public partial class thread : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            Thread thread = new Thread(new ThreadStart(myAsyncProcess));
            thread.Start();
        }

        private void myAsyncProcess() {
            // Long running process
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文