Solved

translate code about PrinterQueueWatch from Vb.net to C#

Posted on 2011-09-14
8
1,110 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

862 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

23 Experts available now in Live!

Get 1:1 Help Now