I tried to print formatted HTML using WebBrowser class. After the print, I want to close the application. If I tried to use close the application the printing is not working. I tried using the timer also nothing works.
Please find the code below.
static void Main(string[] args) {
var b = new Program();
string appPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
b.runBrowserThread("file://" + appPath + "/receipt.html");
}
private void runBrowserThread(string url) {
var th = new Thread(() => {
var br = new WebBrowser();
br.DocumentCompleted += browser_DocumentCompleted;
br.Navigate(url);
Application.Run();
});
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
var br = sender as WebBrowser;
br.Print();
//Application.ExitThread();
Environment.Exit(0);
}