how to write an event on variable value change?

how to write an event on variable value change I have a class level variable declared and then it's value changed (it is changed from other class object) i need that it raise an event Is that possible and how it's done




Answer this question

how to write an event on variable value change?

  • B Letts

    well that's good example about BW but still i need to figure out how to raise event on variable value update

    i Have found same question on google. Here is the link:

    http://director-online.com/forums/read.php 2,14108,16412

    I need code sample of variable watcher in VB.NET



  • raghu_grdr

    I will give short description of my app Maybe it will be easyer to help me:

    All app long tasks is executed on backGround worker control and when app is started it creates an object of class B wich monitors some fileactivity on certain directorys So basicly i have 3 threads main thread ,background worker thread and class B wich has two more references to timer controls.

    When timer function spots some activity it collects data and passes it back to class B there it is analyzed and if needed added to may arraylist of collections with other data(arraylist has reference to class A or is passed from class A) The updated arraylist is passed back automaticly. Then i need to reload my listview control on class A (User interface and some functions) This task is writen on background worker control And if i exetute BW from event raised on class B it never raises the complete event because class B stil exists and timers are still active So i have may background thread busy and any further operations rezult in error because BW can do only one task at a time. So i thougt it would be good that i figure out a way how tu raise event from class A when the arraylist variable is updated.

    Maybe it sounds little confusing or silly but i'm new on multithreading (first time using BW) and quite new to VB.NET so plz be patient and thank you for your time and advice



  • Pwint

    Turn the variable in a property and add an event to the class that you raise when the property changes. For example:

    Public Class Class1
    Public Event MyPropertyChanged()
    Private mProperty As Integer
    Public Property MyProperty() As Integer
    Get
    Return mProperty
    End Get
    Set(ByVal value As Integer)
    If value <> mProperty Then
    mProperty = value
    RaiseEvent MyPropertyChanged()
    End If
    End Set
    End Property
    End Class



  • EnigMa_AnGeL

    This article might be a good example...



  • Ashishkalvade

    and if i pass a variable from class A to class B And i need to monitor it. When class B changes variable value i need event to be raised in class A thats what i really need is it possible

  • Wolfgang Kamir

    As long as class B knows about class A (i.e.: is derived or has a object reference to A), it can call a friend function in class A that calls RaiseEvent. If neither applies, class B could raise an event that is caught by class A which, in turn, calls RaiseEvent on its own event. That requires that class A has a reference to an instance of B, which it should in your case. Tell us which it is and we'll provide a code sample if you need it.



  • how to write an event on variable value change?