0

In VB6 we have the below code.

g_CTimer.TimerID = SetTimer(0&, 0&, g_CTimer.Interval, AddressOf TimerProc)

The TimerProc method is as below

Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
    On Error Resume Next

    If g_CTimer Is Nothing Then Exit Sub
    g_CTimer.ThatTime

End Sub

How do we convert that call "AddressOf TimerProc" in C#.

Thanks in Advance.

Regards Achyuth

Achyuth
  • 41
  • 7
  • Just remove it. Method groups are implicitly converted to delegates. [`SetTimer(0, 0, g_CTimer.Interval, TimerProc)`] – JosephHirn Jul 30 '13 at 12:26
  • Use the [pinvoke.net](http://www.pinvoke.net/default.aspx/user32/SetTimer.html) web site to find proper declarations. But just don't bother with this, the .NET Timer class already takes care of this for you. – Hans Passant Jul 30 '13 at 13:19

1 Answers1

1

In C# you can just omit the AddressOf keyword. In VB.NET it explicitly implies that you are sending the method pointer as an argument (a pointer to TimerProc, in this case). In C# you can just use the method name directly.

That said, you're probably better off just re-implementing this with a normal timer (Windows.Forms.Timer or some other).

J...
  • 30,968
  • 6
  • 66
  • 143
  • @Achyuth you will still have four arguments - `AddressOf TimerProc` is one argument, you replace it with `TimerProc`. – J... Jul 30 '13 at 12:35