Application exiting on printing

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top