0

I want to prepare an HTML page for printing I want execute DocumentCompleted in a loop,but it won't run until the end of the loop.To be sent each time the print command loop is executed.

string _filesPrint = "";
string _filesDesign = System.IO.File.ReadAllText(Path.GetDirectoryName(Application.ExecutablePath) + @"\printerDesign\files.html");
int countFilesPrepare = 0;
foreach (DataRow _dtRows in _dt.Rows)
{
    _filesPrint = _filesPrint + _filesDesign;
    countFilesPrepare++;
    lblFilesPrepare.Text = "total files for print : " + 
    countFilesPrepare.ToString();
    lblFilesPrepare.Update();
    if (countFilesPrepare % 2==0)
    {
        myWebBrowser.DocumentCompleted += myWebBrowser_DocumentCompleted;// this line not execute
        myWebBrowser.DocumentText = (_filesPrint);
        _filesPrint = "";
        _filesDesign = System.IO.File.ReadAllText(Path.GetDirectoryName(Application.ExecutablePath) + @"\printerDesign\files.html");
        myWebBrowser = new WebBrowser();
    }
}
if (_filesPrint != "")
{
    myWebBrowser.DocumentCompleted += myWebBrowser_DocumentCompleted;
    myWebBrowser.DocumentText = (_filesPrint);

}
Nima Derakhshanjan
  • 1,380
  • 9
  • 24
  • 37
Hamid
  • 1
  • 3
  • You can try [Google Translate](https://translate.google.com/)... – BionicCode Sep 21 '19 at 08:23
  • You can simplify greatly the loading and processing of multiple documents in a loop by using an async version of `DocumentCompleted` event, that can by awaited. Look [here](https://stackoverflow.com/questions/57092336/threading-concept-to-improve-the-webbrowsers-url-navigation-process-in-c-sharp/57102766#57102766) for the `DocumentCompletedAsync` extension method that does exactly this. – Theodor Zoulias Sep 22 '19 at 10:01

0 Answers0