且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

请求完成后的处理

更新时间:2022-01-20 06:00:08

您需要以某种方式启动其他线程.放置在管道前面的中间件将使您有机会在请求完成之前进行工作.如果您从那里旋转一个线程,那么它可能会起作用.

You need to start somehow a different thread. A middleware put in front of the pipeline will give you the chance to do work just before the request completes. If you spin a thread, from there, then it might work.

您可能想使用某种生产者-消费者模式这样您就不会杀死服务器.否则,如果每个请求都启动了一个立即运行的线程,并且您同时有多个请求,则可能最终会耗尽资源.生产者-消费者将帮助您限制这项工作.

You probably want to use some sort of producer-consumer pattern so you don't kill your server. Otherwise, if every request starts a thread that does work immediately and you have many requests at the same time, you might end up running out of resources. A producer-consumer would help you throttle that work.

如果您不着急,可以等一周左右,等我交付ASP.NET的文件记录器,然后您会在此处看到类似的实现.

If you're not in a hurry, you can wait another week or so when I'll deliver the file logger for ASP.NET and then you'll see a similar implementation there.