Solved

translate code about PrinterQueueWatch from Vb.net to C#

Posted on 2011-09-14
8
1,119 Views
Last Modified: 2013-12-17
HI,
I have to translate from Vb.Net to C#
the attached code,
I cannot transalte the part about Hanlder.

EXAMPLE
Imports PrinterQueueWatch

Module modPrintPDF

    Public Function PrintPDF(ByVal PDFFile As String, ByVal Printer As String, ByVal Timeout As Integer) As Integer

        If PrinterName.Trim.Length = 0 Then
            PrinterName = (New System.Drawing.Printing.PrinterSettings).PrinterName
        End If

        Dim Proc AS New System.Diagnostics.Process

        Proc.EnableRaisingEvents = True
        Proc.StartInfo.FileName = PDFFile
        Proc.StartInfo.Arguments = Chr(34) + PrinterName + Chr(34)
        Proc.StartInfo.Verb = "PrintTo"
        Proc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
        Proc.StartInfo.CreateNoWindow = True

        ' Now start monitoring the printer's queue.
        Dim Monitor As New PrinterQueueWatch.PrinterMonitorComponent
        Monitor.MonitorJobAddedEvent = False
        Monitor.MonitorJobDeletedEvent = False
        Monitor.MonitorJobSetEvent = True
        Monitor.MonitorJobWrittenEvent = False
        Monitor.MonitorPrinterChangeEvent = False
        AddHandler Monitor.JobSet, AddressOf SetPrintJob
        Monitor.DeviceName = PrinterName

        ' Now that I am watching, start up Acrobat.
        Proc.Start()

        Do While Timeout > 0 AndAlso Not Proc.HasExited
            System.Threading.Thread.Sleep(1000)
            Timeout -= 1
        Loop

        ' Stop monitoring.
        RemoveHandler Monitor.JobSet, AddressOf SetPrintJob
        Monitor = Nothing

        If Not Proc.HasExited Then
            Debug.Print("Killing process")
            Proc.Kill()
        End If

        Debug.WriteLine("Closing process")
        Proc.Close()

        Return 0
    End Function
    Public Function PrintPDF(ByVal PDFFile As String) As Integer
        Return PrintPDF(PDFFile, "", 60)
    End Function
    Public Function PrintPDF(ByVal PDFFile As String, ByVal Timeout As Integer) As Integer
        Return PrintPDF(PDFFile, "", Timeout)
    End Function

    Private Sub SetPrintJob(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Print job is set to print.
        System.Threading.Thread.Sleep(500)
        Proc.Kill()
    End Sub
End Module

Open in new window

0
Comment
Question by:bobdylan75
  • 5
  • 3
8 Comments
 
LVL 3

Accepted Solution

by:
Srm74 earned 500 total points
ID: 36535170
AddHandler Monitor.JobSet, AddressOf SetPrintJob

==>

Monitor.JobSet += new EventHandler(SetPrintJob);
And the implement the "SetPrintJob"..

----

RemoveHandler Monitor.JobSet, AddressOf SetPrintJob

==>

Monitor.JobSet -= SetPrintJob;

Hope it helps

0
 

Author Comment

by:bobdylan75
ID: 36535321
Srm/4 thanks,
could you implement the SetprintJob function which is in the code?
thank you very much.
0
 
LVL 3

Assisted Solution

by:Srm74
Srm74 earned 500 total points
ID: 36535352
Something like this.. :-)

Private SetPrintJob(object sender, EventArgs e)
{
        //Print job is set to print.
        System.Threading.Thread.Sleep(500);
        Proc.Kill();
}
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:bobdylan75
ID: 36535497
But my compiler (VS2005) say to me that
the function of the class has to have a return type...
0
 
LVL 3

Expert Comment

by:Srm74
ID: 36535505
You need to add 'void' after private..

private void SetPrintJob(object sender, EventArgs e)
0
 

Author Comment

by:bobdylan75
ID: 36535520
Ok if I put a Void type it works properly thanks
0
 

Author Closing Comment

by:bobdylan75
ID: 36535524
thanks
0
 

Author Comment

by:bobdylan75
ID: 36535533
I used PrintJobEventHandler instead of EventHandler
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question