I am writing an app that prints out a (rendered) HTML page to every printer that is installed on the computer the app is running on. I do this by creating a WebBrowser, calling print() on it, and then closing the form. I do this for each printer that is installed on that computer.
My problem is that when I call attempt to close the form, the page does not get printed. Any ideas on how I can make the printing an independent background process, so that I can close the form while it is still printing?
This is the code that I currently have in the form:
public PrintForm()
{
InitializeComponent();
string doc = "C:\\Path\\To\\file.htm";
browser.Url = new Uri(doc);
}
private void PrintForm_Shown(object sender, EventArgs e)
{
Thread t = new Thread(browser.Print);
t.IsBackground = false;
t.Start();
this.Close();
}
I have another class that toggles each of the installed printers as the default printer (the only way to programmatically bypass a print dialogue) and then calls
Applicated.Run(new PrintForm());
Really pretty simply code. Just having a bit of trouble with it.