HighTechTalks DotNet Forums  

Printing cause application thread exiting

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss Printing cause application thread exiting in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
pascal.fluck@gmail.com
 
Posts: n/a

Default Printing cause application thread exiting - 11-29-2007 , 10:25 AM






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

Reply With Quote
  #2  
Old   
Bob Powell [MVP]
 
Posts: n/a

Default Re: Printing cause application thread exiting - 12-01-2007 , 05:32 AM






I suggest that you update your printer drivers. This may be causing the
problem.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


<pascal.fluck (AT) gmail (DOT) com> wrote

Quote:
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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.