Reputation: 733
I have written a thread to check if there are any freeze in mainform. I am doing this because sometimes TWebbrowser freezes main UI. I think it is because of a javascript and i can not reproduce this problem.
What i need is to safely stop TWebbrowser's job. Actually it should be in a loop or waiting for something but it freezes somehow. Well what i need is to detect and kill the browser and recreate it.
This is how i detect the freeze:
bFreeze := SendMessageTimeout(hwn, WM_NULL, 0, 0, SMTO_ABORTIFHUNG OR SMTO_BLOCK, TIME_OUT, iRes) <= 0;
Any advice will be greatly appreciated.
Thanks
Upvotes: 0
Views: 122
Reputation: 613511
You are running the browser control from your program's main thread. Any attempt to forcibly terminate the browser thread will bring down your entire program. If you have code that can hang, and you wish to recover from that, then it is just not realistic to expect to run that code from your main thread.
Modern browsers deal with this problem by isolating each page in a distinct process. Then if that page hangs in some way, or crashes, the page process can be killed without impacting on the other pages open in the browser.
If you really want to have similar robustness you'll need to have a similar architecture. You might be tempted to think you can isolate a page in a thread within a single process but in practise this doesn't give sufficient isolation.
Perhaps a more tenable solution is to avoid the hang in the first place. Maybe you need to make sure that you are using the latest browser engine. Did you specify that in the browser feature emulation registry key?
Upvotes: 2