-1

I have two timers I AddHandler to ShowData

how I know which timer call the event

 Dim TM1, TM2 As System.Timers.Timer

        TM1 = New Timers.Timer(600000) 
        AddHandler TM1.Elapsed, AddressOf ShowData
        TM1.Start()

        TM2 = New Timers.Timer(15000) 
        AddHandler TM2.Elapsed, AddressOf ShowData
        TM2.Start()


 Private Sub ShowData()
  Dim T as string
  T =   ' here I want object name that called this event 
 'code         
 End Sub
MG_1
  • 41
  • 5

1 Answers1

3

You have to use the correct signature, then you have the sender-argument which is the timer:

Private Sub ShowData(sender As Object, e As System.Timers.ElapsedEventArgs)
    Dim timer = CType(sender, System.Timers.Timer)
    If timer Is TM1 Then

    ElseIf timer Is TM2 Then

    ElseIf timer Is TMEmail Then

    End If
End Sub

For the sake of completeness(and your C# tag):

private void ShowData(Object sender, System.Timers.ElapsedEventArgs e)
{
    var timer = (System.Timers.Timer) sender;
    if(timer == TM1)
    {

    }
    else if (timer == TM2)
    {

    }
    else if(timer == TMEmail)
    {

    }
} 
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • That work good but I have other problem when I try make this on object come from other class give me this msg : does not have signature compatible with delegate – MG_1 Dec 15 '15 at 13:15
  • 1
    @user2842091: your next problem is not clear, maybe you should ask another question and include an example. – Tim Schmelter Dec 15 '15 at 13:31