Solved

translate code about PrinterQueueWatch from Vb.net to C#

Posted on 2011-09-14
8
1,107 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now