问题
I am trying to create screen captures of web pages in a Delphi server application (XE2) using TWebBrowser. The screen captures are initiated via web service calls to my server, so to preserve scalability, I would like to service the requests without relying on critical sections or Application.ProcessMessages to do the web page rendering.
Can this be done with TWebBrowser?
回答1:
I've done this already in a number of objects, and sadly enough the TWebBrowser object ties very much into it's parent object, and specifically its HWND handle. (see also TWebBrowser.HandleNeeded)
The best results I've had was by encapsulating the TWebBrowser and form in an ActiveX library, so the 'message pump' behind it is separated from the main application. This way ActiveX/COM handles all threading and synchronization issues.
回答2:
Try putting the TWebbrowser in a separate exe. That would move that to a different thread/process and you gain modularity, scalability and performance. The web service can communicate with the process that has the webbrowser using IPC or messaging.
Use a queue system to track assignment and completion of capture tasks to the screen capture process or run the exe for each site to capture.
Another advantage you get using this method is if the capture program crashes, the web service would still be available to take requests. The web service can check if the exe process is in memory before assigning a task and if it is not (crashed or not started) it can start the exe on its own.
来源:https://stackoverflow.com/questions/17657351/can-the-twebbrowser-be-used-in-a-thread-in-delphi-without-application-processmes