Solved

translate code about PrinterQueueWatch from Vb.net to C#

Posted on 2011-09-14
8
1,126 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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