InfoPath Print MessageBox

  • Thread starter Thread starter stnfck
  • Start date Start date
S

stnfck

I am attempting to print out various infopath views using a print driver that
prints to an image via the folowing code:


Print(false);

//MessageBox.Show("Printing: "+infos.Name);

bool canAccess = false;
while (!canAccess) {
try {
Bitmap tiff = new Bitmap(fileLocation); //
Errors here because the file doesnt exist
MemoryStream stream = new MemoryStream();
tiff.Save(stream,
System.Drawing.Imaging.ImageFormat.Tiff);
string image =
Convert.ToBase64String(stream.ToArray());
stream.Close();
tiff.Dispose();

xmlInfo += image;

canAccess = true;
File.Delete(fileLocation);
} catch (Exception e) {
System.Threading.Thread.Sleep(1000);
}
}

Youll notice that I have a loop checking for when the image becomes
available so that I can bring it in as a string and append it to the xml
document for processing.

Here is the weird part, if I do it as it shows above it never creates the
image, it will just sit in that Thread loop forever becuase the Bitmap cannot
access the file.

BUT! If I uncomment that MessageBox that would just prompt before it does
anything it works perfectly.

I have tried sleeping right after the print to see if it just needed to take
some time. Doesnt Work.

I have tried printing on another thread, and that doesnt work.

So my question is, is does anyone know what MessageBox.Show is doing that
would let that process continue?

Thanks in advance!
 
I ended up hooking into the Windows Dialog using SetWindowsHookEx to close
any messageboxes that displayed but this is a bit of a hack. Anyone know how
IO operations would hang a Print Thread, but how also making a call to
MessageBox in user32.dll would somehow seperate it enough to continue?
 
Back
Top