Application exiting on printing

  • Thread starter Thread starter pascal.fluck
  • Start date Start date
P

pascal.fluck

Hi all,

I have a strange problem:
When my application print something with
System.Drawing.Printing.PrintDocument(), my application thread
(MessageLoop) is going down.
I know that because I putted an event on Application.ThreadExit and
this event is launched when printing.

What is also strange is if I remove the small printing dialog, it
doesn't happend...

Here is a small test code:
<code>
Public Class Form1

Public Sub New()

' This call is required by the Windows Form Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call.
AddHandler Application.ThreadExit, AddressOf Me.OnThreadExit
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
ShowOtherWin(Nothing)
End Sub

Private Sub OnPrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
e.Graphics.DrawLine(Pens.Black, 10, 10, 100, 100)
End Sub

Private Sub ShowOtherWin(ByVal state As Object)
Dim printDocument As New
System.Drawing.Printing.PrintDocument()
AddHandler printDocument.PrintPage, AddressOf Me.OnPrintPage
'printDocument.PrintController = New
System.Drawing.Printing.StandardPrintController() ' Hide small dialog
"Printing..."
printDocument.Print()
End Sub

Private Sub OnThreadExit(ByVal sender As Object, ByVal e As
EventArgs)
Console.WriteLine("Application Exited")
End Sub

End Class
</code>

Any idee???

Thanks a lot.

Pascal
 
Back
Top