Solved

translate code about PrinterQueueWatch from Vb.net to C#

Posted on 2011-09-14
8
1,131 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

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.

Question has a verified solution.

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

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 …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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