开发者

Multithreading HttpListern resume sleeping thread

开发者 https://www.devze.com 2023-04-03 06:37 出处:网络
I have an HttpListener that for each request received launches a winform and returns an array of byte representing an image. This image is taken by the winform once it executes some commands parsed fr

I have an HttpListener that for each request received launches a winform and returns an array of byte representing an image. This image is taken by the winform once it executes some commands parsed from request's querystring. Any winforms is executing inside a different Thread.

Right now after the winform has done its job, it comes up with an array of byte as the response and then its thread died开发者_如何学编程, if the same user makes a new request a new thread (with a new winform) is created.

I'm guessing if I can maintain each thread, using an ID for each user (IP address, a GUID, cookie), so I don't have to recreate the winform every time and at the same time the winform will maintain previous state.

Is it possible? Or I have to move to another direction or design?


You could change the design to workers/tasks approach, defining separately the worker pool (thread+Form) and the task pool. That done, you can decide wether to create a new thread/form pair to handle a task or reuse an existing one, you can choose the number of workers to run, limiting the risk of over consuming the server resources. But using Winforms on a server side is definitely not the best way, as shf301 pointed out.

0

精彩评论

暂无评论...
验证码 换一张
取 消