c# - Closing application after event -
i'm using .net webbrowser in order render html page , save bitmap (got code stackoverflow post). problem thread starts web browser never closes.
the thread should close when startbrowser method finishes never because application.run never ends.
my question : how close application after webbrowser finishes rendering page , saves bitmap ? adding application.exit();
inside documentcompleted event doesn't seem work.
code:
public class dotnetrenderer : ihtmlrenderer { static bitmap bmp; thread th; public void initializerenderer() { } public bitmap renderhtml(string htmlcontent) { th = new thread(() => startbrowser(htmlcontent)); th.setapartmentstate(apartmentstate.sta); th.start(); th.join(); return bmp; } public static void startbrowser(string source) { var webbrowser = new webbrowser(); webbrowser.scrollbarsenabled = false; webbrowser.documentcompleted += webbrowser_documentcompleted; webbrowser.documenttext = source; application.run(); } static void webbrowser_documentcompleted(object sender, webbrowserdocumentcompletedeventargs e) { var webbrowser = (webbrowser)sender; bmp = new bitmap(webbrowser.width, webbrowser.height); webbrowser.drawtobitmap(bmp, new system.drawing.rectangle(0, 0, bmp.width, bmp.height)); application.exitthread(); } }
application.exitthread() want, don't know why webbrowser width , height (250,250) regardless of input html.
Comments
Post a Comment