-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Microsoft's latest Copilot addition could change how you gather insights
By Usama Jawad96,
- microsoft
- microsoft 365 copilot
- (and 8 more)
- 0 replies
- 0 views
-
Microsoft Forms now adds a way to generate answers to quiz questions via Copilot
By John Callaham,
- microsoft
- microsoft forms
- (and 2 more)
- 0 replies
- 0 views
-
Copilot can now offer suggestions to make better quizzes and surveys in Microsoft Forms
By John Callaham,
- microsoft
- microsoft forms
- (and 2 more)
- 0 replies
- 0 views
-
Microsoft Forms adds support for setting up rules to answer survey questions
By John Callaham,
- microsoft
- microsoft 365
- (and 2 more)
- 0 replies
- 0 views
-
Microsoft Forms finally enables collaboration feature for Microsoft account holders
By pradeepviswav,
- microsoft
- microsoft forms
- (and 5 more)
- 0 replies
- 0 views
-
Question
+Red King Subscriber²
Point of application,
Render Provided html string and print it using Internet Explorer, quickly in the background.
Problem,
WebBrowser control requires to be run in an STA thread stopping this thread (after Disposing the Web Browser) causes an IE script error.
I have a class which starts a WebBrowser Control in an STA thread,
class RenderHtml : System.Windows.Forms.ApplicationContext { // stuff private WebBrowser browser = null; // more stuff public RenderHtml() { renderThread = new Thread(Run); renderThread.SetApartmentState(System.Threading.ApartmentState.STA); renderThread.Start(); } private void Run() { // Error Checking Omitted browser = new WebBrowser(); browser.DocumentCompleted += HasRendered; browser.ScriptErrorsSuppressed = true; Application.Run(this);Then, I give pipe it Html to load,
public void RenderNew(string html, AutoResetEvent resultEvent) { // Error Checking Omitted browser.DocumentText = html; browser.Refresh(); // AutoResetEvent Logic Omitted }Then after it finished rendering, I tell it to print to a specific virtual printer.
That all works.
So now, I need to dispose of it.
This is what I have right now
protected override void Dispose(bool disposing) { lock (locko) { if (renderThread != null) { renderThread.Abort(); renderThread = null; return; } } browser.DocumentCompleted -= HasRendered; System.Runtime.InteropServices.Marshal.Release(browser.Handle); browser.Dispose(); base.Dispose(disposing); } public void Stop() { resultEvent.Dispose(); browser.Stop(); ExitThread(); Dispose(); }The problem is with both renderThread.Abort() and ExitThread() - I have to commit both out not to get an error.
Both of these fail due to the WebBrowser control.
I don't feel like providing a screenshot, so here is the text,
The error comes from IE itself,
So, after calling Dispose methods including the WebBrowsers dispose method.
I try to stop the thread. Which gives me this error.
If I did NOT provide any html to render I think (been a long time) there is no Script Error.
But then, it completely kills the point of the application!
Note I do suppress Script Errors - when I created the WebBrowser.
browser.ScriptErrorsSuppressed = true;Also, does anyone know of a way to provide images to the WebBrowser control without going through saving them to disk?
Link to comment
https://www.neowin.net/forum/topic/1151872-function-expected-ie10-script-error-on-disposing-of-webbrowser-st/Share on other sites
2 answers to this question
Recommended Posts