Detect event generated in another class

4

I have a class (in VB) that returns an event of TimeOut , that is, if the time it pops up it returns an event with a string containing the data I need using RaiseEvent. How can I handle this event in the main class which is in C #. I tried using delegate but I could not. Thank you.

Code:

Public Class Dados
    Public Event _TrateTimeOut(ByVal dados As Dados)

    Private Sub MonitoraTimeOut()
        If TimeOut Is Nothing Then

            TimeOut = New Timers.Timer
            TimeOut.Interval = 10000
            AddHandler TimeOut.Elapsed, AddressOf TrateTimeOut
            TimeOut.Start()
        Else
            TimeOut.Stop()
            TimeOut.Start()
        End If

    End Sub

    Private Sub TrateTimeOut()
        RaiseEvent _TrateTimeOut(Me)
    End Sub
End Class
    
asked by anonymous 09.06.2014 / 21:33

2 answers

1

Friend, In the comments you complain about the event in an infinite loop and your question has the following passage: "if time bursts it returns a contented event with a string with the data I need using RaiseEvent"

It will pop up yes, every 10 seconds and indefinitely. But it seems like you want it to be one time.

I would use the gypsy version optimally:

public class ConsumidorComponenteVBZao { public ConsumidorComponenteVBZao() { var dados = new Dados(); dados._TrateTimeOut += FuncaoQueTrataOEvento; } private void FuncaoQueTrataOEvento(object sender, EventArgs e) { // Faça aqui o tratamento de dados, e tal. } }

And in your VB, it would use a Thread and not a timer to trigger events at each interval.

    
09.07.2014 / 23:03
0

I do not know your C # class, but I'll assume something like this:

public class ClasseEmCSharp {
    public Dados dados = new Dados();
    public delegate void EventHandler(object sender, EventArgs e);

    public ClasseEmCSharp() {
        dados._TrateTimeOut += new EventHandler(FuncaoQueTrataOEvento);
    }

    private void FuncaoQueTrataOEvento(object sender, EventArgs e) 
    {
        // Faça aqui o tratamento de dados, e tal.
    }
}

It's a little weird about the treatment, but that's basically it.

    
09.06.2014 / 22:14