Bubbling a status message to the UI

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pamelafluente@libero.it

    #1

    Bubbling a status message to the UI

    Hi guys,

    After the Exception question, I have another one, strictly related.
    I would also like what is your preferred device
    to bubble a message (not by exception) to the user Interface.

    Assume for instance the following simple schema. What is the best way
    to bubble the "Status" string message to the UI ? Please suggest
    appropriate
    code changes.

    I guess that different programmers might have different ideas on how to
    that
    in the most flexible way ...

    -P

    '--------------------------------- SAMPLE CODE -----------------------

    Public Class Form1

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click

    Try
    With New SomeProcessor
    .SomeTask()

    ' I want for instance the "Status" issued by SomeOtherTask
    ' to be appended to a TextBox on this User Interface
    ' What's the best way to bubble the message here

    End With

    Catch ex As Exception
    Me.RichTextBox1 .AppendText(ex. Message)
    End Try

    End Sub

    End Class


    'The following is in separate files

    Class SomeProcessor

    Sub SomeTask()
    With New SomeOtherProces sor
    Try
    .SomeOtherTask( )
    Catch ex As Exception
    Throw
    End Try

    End With
    End Sub

    End Class


    Class SomeOtherProces sor

    Sub SomeOtherTask()

    Try
    Dim Status As String = "This operation was successful"
    Catch ex As Exception
    Throw
    End Try

    End Sub

    End Class

  • tomb

    #2
    Re: Bubbling a status message to the UI

    Pass the textbox as a reference to the called proc, or an object that
    can throw an event when changed so you can updated the status control.

    Tom

    pamelafluente@l ibero.it wrote:
    >Hi guys,
    >
    >After the Exception question, I have another one, strictly related.
    >I would also like what is your preferred device
    >to bubble a message (not by exception) to the user Interface.
    >
    >Assume for instance the following simple schema. What is the best way
    >to bubble the "Status" string message to the UI ? Please suggest
    >appropriate
    >code changes.
    >
    >I guess that different programmers might have different ideas on how to
    >that
    >in the most flexible way ...
    >
    >-P
    >
    >'--------------------------------- SAMPLE CODE -----------------------
    >
    >Public Class Form1
    >
    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    >System.EventAr gs) Handles Button1.Click
    >
    Try
    With New SomeProcessor
    .SomeTask()
    >
    ' I want for instance the "Status" issued by SomeOtherTask
    ' to be appended to a TextBox on this User Interface
    ' What's the best way to bubble the message here
    >
    End With
    >
    Catch ex As Exception
    Me.RichTextBox1 .AppendText(ex. Message)
    End Try
    >
    End Sub
    >
    >End Class
    >
    >
    >'The following is in separate files
    >
    >Class SomeProcessor
    >
    Sub SomeTask()
    With New SomeOtherProces sor
    Try
    .SomeOtherTask( )
    Catch ex As Exception
    Throw
    End Try
    >
    End With
    End Sub
    >
    >End Class
    >
    >
    >Class SomeOtherProces sor
    >
    Sub SomeOtherTask()
    >
    Try
    Dim Status As String = "This operation was successful"
    Catch ex As Exception
    Throw
    End Try
    >
    End Sub
    >
    >End Class
    >
    >
    >

    Comment

    • pamelafluente@libero.it

      #3
      Re: Bubbling a status message to the UI

      Hi tom, thanks

      must say I thought about this solution (perhaps the ByRef is optional,
      right?). But then I
      have some problem when I want to use the code both with Winform or
      WebForm.

      What I mean that what I would like to bubble is probably
      just the message because the interface could be different.

      So I wanted your opinions on what is a good method to do
      this in such a way we can deal with different UIs.

      For instance the Exception mechanism allows to do that.

      I was wondering if something similar could be done for a, say, "status"
      messages (ie. not accompanied by exceptions).

      Thanks you very much,

      -P

      tomb ha scritto:
      Pass the textbox as a reference to the called proc, or an object that
      can throw an event when changed so you can updated the status control.
      >
      Tom
      >
      pamelafluente@l ibero.it wrote:
      >
      Hi guys,

      After the Exception question, I have another one, strictly related.
      I would also like what is your preferred device
      to bubble a message (not by exception) to the user Interface.

      Assume for instance the following simple schema. What is the best way
      to bubble the "Status" string message to the UI ? Please suggest
      appropriate
      code changes.

      I guess that different programmers might have different ideas on how to
      that
      in the most flexible way ...

      -P

      '--------------------------------- SAMPLE CODE -----------------------

      Public Class Form1

      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles Button1.Click

      Try
      With New SomeProcessor
      .SomeTask()

      ' I want for instance the "Status" issued by SomeOtherTask
      ' to be appended to a TextBox on this User Interface
      ' What's the best way to bubble the message here

      End With

      Catch ex As Exception
      Me.RichTextBox1 .AppendText(ex. Message)
      End Try

      End Sub

      End Class


      'The following is in separate files

      Class SomeProcessor

      Sub SomeTask()
      With New SomeOtherProces sor
      Try
      .SomeOtherTask( )
      Catch ex As Exception
      Throw
      End Try

      End With
      End Sub

      End Class


      Class SomeOtherProces sor

      Sub SomeOtherTask()

      Try
      Dim Status As String = "This operation was successful"
      Catch ex As Exception
      Throw
      End Try

      End Sub

      End Class

      Comment

      • tomb

        #4
        Re: Bubbling a status message to the UI

        That would be the choice of using an object that raises an event when it
        is changed. Then whatever parent calls the proc, it passes that
        object. If the object is changed, the parent can respond to it any way
        it wants.

        As such:
        private withevents myObject as whatever

        thisvalue = someproc( myObject )


        Tom


        pamelafluente@l ibero.it wrote:
        >Hi tom, thanks
        >
        >must say I thought about this solution (perhaps the ByRef is optional,
        >right?). But then I
        >have some problem when I want to use the code both with Winform or
        >WebForm.
        >
        >What I mean that what I would like to bubble is probably
        >just the message because the interface could be different.
        >
        >So I wanted your opinions on what is a good method to do
        >this in such a way we can deal with different UIs.
        >
        >For instance the Exception mechanism allows to do that.
        >
        >I was wondering if something similar could be done for a, say, "status"
        >messages (ie. not accompanied by exceptions).
        >
        >Thanks you very much,
        >
        >-P
        >
        >tomb ha scritto:
        >
        >
        >
        >>Pass the textbox as a reference to the called proc, or an object that
        >>can throw an event when changed so you can updated the status control.
        >>
        >>Tom
        >>
        >>pamelafluente @libero.it wrote:
        >>
        >>
        >>
        >>>Hi guys,
        >>>
        >>>After the Exception question, I have another one, strictly related.
        >>>I would also like what is your preferred device
        >>>to bubble a message (not by exception) to the user Interface.
        >>>
        >>>Assume for instance the following simple schema. What is the best way
        >>>to bubble the "Status" string message to the UI ? Please suggest
        >>>appropriat e
        >>>code changes.
        >>>
        >>>I guess that different programmers might have different ideas on how to
        >>>that
        >>>in the most flexible way ...
        >>>
        >>>-P
        >>>
        >>>'--------------------------------- SAMPLE CODE -----------------------
        >>>
        >>>Public Class Form1
        >>>
        >> Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
        >>>System.Event Args) Handles Button1.Click
        >>>
        >> Try
        >> With New SomeProcessor
        >> .SomeTask()
        >>>
        >> ' I want for instance the "Status" issued by SomeOtherTask
        >> ' to be appended to a TextBox on this User Interface
        >> ' What's the best way to bubble the message here
        >>>
        >> End With
        >>>
        >> Catch ex As Exception
        >> Me.RichTextBox1 .AppendText(ex. Message)
        >> End Try
        >>>
        >> End Sub
        >>>
        >>>End Class
        >>>
        >>>
        >>>'The following is in separate files
        >>>
        >>>Class SomeProcessor
        >>>
        >> Sub SomeTask()
        >> With New SomeOtherProces sor
        >> Try
        >> .SomeOtherTask( )
        >> Catch ex As Exception
        >> Throw
        >> End Try
        >>>
        >> End With
        >> End Sub
        >>>
        >>>End Class
        >>>
        >>>
        >>>Class SomeOtherProces sor
        >>>
        >> Sub SomeOtherTask()
        >>>
        >> Try
        >> Dim Status As String = "This operation was successful"
        >> Catch ex As Exception
        >> Throw
        >> End Try
        >>>
        >> End Sub
        >>>
        >>>End Class
        >>>
        >>>
        >>>
        >>>
        >>>
        >
        >
        >

        Comment

        • GhostInAK

          #5
          Re: Bubbling a status message to the UI

          Hello pamela,

          I don't like tomb's solution. You should never pass in an object that listens
          for changes. I would suggest simply raising an event from within your processor.


          -Boo
          Hi guys,
          >
          After the Exception question, I have another one, strictly related.
          I would also like what is your preferred device
          to bubble a message (not by exception) to the user Interface.
          Assume for instance the following simple schema. What is the best way
          to bubble the "Status" string message to the UI ? Please suggest
          appropriate
          code changes.
          I guess that different programmers might have different ideas on how
          to
          that
          in the most flexible way ...
          -P
          >
          '--------------------------------- SAMPLE CODE -----------------------
          >
          Public Class Form1
          >
          Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
          As System.EventArg s) Handles Button1.Click
          >
          Try
          With New SomeProcessor
          .SomeTask()
          ' I want for instance the "Status" issued by SomeOtherTask
          ' to be appended to a TextBox on this User Interface
          ' What's the best way to bubble the message here
          End With
          >
          Catch ex As Exception
          Me.RichTextBox1 .AppendText(ex. Message)
          End Try
          End Sub
          >
          End Class
          >
          'The following is in separate files
          >
          Class SomeProcessor
          >
          Sub SomeTask()
          With New SomeOtherProces sor
          Try
          .SomeOtherTask( )
          Catch ex As Exception
          Throw
          End Try
          End With
          End Sub
          End Class
          >
          Class SomeOtherProces sor
          >
          Sub SomeOtherTask()
          >
          Try
          Dim Status As String = "This operation was successful"
          Catch ex As Exception
          Throw
          End Try
          End Sub
          >
          End Class
          >

          Comment

          • pamelafluente@libero.it

            #6
            Re: Bubbling a status message to the UI

            Hi Ghost,

            can you make more precise what you mean. Are you talking about a shared
            event?

            Actually the idea of an additional argument does not make me
            enthusiastic,
            but also the idea of some shared event is quite disgusting (to me).

            Could you clarify your suggestion, by applying that to my simple
            example?

            -P

            GhostInAK ha scritto:
            Hello pamela,
            >
            I don't like tomb's solution. You should never pass in an object that listens
            for changes. I would suggest simply raising an event from within your processor.
            >
            >
            -Boo
            >
            Hi guys,

            After the Exception question, I have another one, strictly related.
            I would also like what is your preferred device
            to bubble a message (not by exception) to the user Interface.
            Assume for instance the following simple schema. What is the best way
            to bubble the "Status" string message to the UI ? Please suggest
            appropriate
            code changes.
            I guess that different programmers might have different ideas on how
            to
            that
            in the most flexible way ...
            -P

            '--------------------------------- SAMPLE CODE -----------------------

            Public Class Form1

            Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
            As System.EventArg s) Handles Button1.Click

            Try
            With New SomeProcessor
            .SomeTask()
            ' I want for instance the "Status" issued by SomeOtherTask
            ' to be appended to a TextBox on this User Interface
            ' What's the best way to bubble the message here
            End With

            Catch ex As Exception
            Me.RichTextBox1 .AppendText(ex. Message)
            End Try
            End Sub

            End Class

            'The following is in separate files

            Class SomeProcessor

            Sub SomeTask()
            With New SomeOtherProces sor
            Try
            .SomeOtherTask( )
            Catch ex As Exception
            Throw
            End Try
            End With
            End Sub
            End Class

            Class SomeOtherProces sor

            Sub SomeOtherTask()

            Try
            Dim Status As String = "This operation was successful"
            Catch ex As Exception
            Throw
            End Try
            End Sub

            End Class

            Comment

            • GhostInAK

              #7
              Re: Bubbling a status message to the UI

              Hello pamela,

              public class Form1

              private sub Button_click( ... )

              Dim tSomeTask as SomeProcessor = New SomeProcessor
              AddHandler tSomeTask.Statu sChange, addressof StatusChangeHan dler

              tSomeTask.Dance MonkeyDance

              end sub

              private sub StatusChangeHan dler(byval tStatus as string)

              textbox1.text = tstatus

              end sub

              end class



              public class SomeProcessor

              public event StatusChange(by val tStatus as string)

              private withevents tSomeOtherProce ssor as SomeProcessor2 = New SomeProcessor2

              private sub StatusChangeHan dler(byval tStatus as string) handles tSomeOtherProce ssor.StatusChan ge
              raiseevent StatusChange(tS tatus)
              end sub

              public sub DanceMonkeyDanc e()
              tSomeOtherProce ssor.DoSomethin g
              end Sub

              end class



              public class SomeOtherProces sor2

              public event StatusChange(by val tStatus as string)

              public sub DoSomething
              ' Change the status.. look at the perdy percolating..
              raiseevent StatusChange("W as that good for you?")
              end sub

              end class
              Hi Ghost,
              >
              can you make more precise what you mean. Are you talking about a
              shared event?
              >
              Actually the idea of an additional argument does not make me
              enthusiastic,
              but also the idea of some shared event is quite disgusting (to me).
              Could you clarify your suggestion, by applying that to my simple
              example?
              >
              -P
              >
              GhostInAK ha scritto:
              >
              >Hello pamela,
              >>
              >I don't like tomb's solution. You should never pass in an object
              >that listens for changes. I would suggest simply raising an event
              >from within your processor.
              >>
              >-Boo
              >>
              >>Hi guys,
              >>>
              >>After the Exception question, I have another one, strictly related.
              >>I would also like what is your preferred device
              >>to bubble a message (not by exception) to the user Interface.
              >>Assume for instance the following simple schema. What is the best
              >>way
              >>to bubble the "Status" string message to the UI ? Please suggest
              >>appropriate
              >>code changes.
              >>I guess that different programmers might have different ideas on how
              >>to
              >>that
              >>in the most flexible way ...
              >>-P
              >>'--------------------------------- SAMPLE CODE
              >>-----------------------
              >>>
              >>Public Class Form1
              >>>
              >>Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
              >>System.EventA rgs) Handles Button1.Click
              >>>
              >>Try
              >>With New SomeProcessor
              >>.SomeTask()
              >>' I want for instance the "Status" issued by SomeOtherTask
              >>' to be appended to a TextBox on this User Interface
              >>' What's the best way to bubble the message here
              >>End With
              >>Catch ex As Exception
              >>Me.RichTextBo x1.AppendText(e x.Message)
              >>End Try
              >>End Sub
              >>End Class
              >>>
              >>'The following is in separate files
              >>>
              >>Class SomeProcessor
              >>>
              >>Sub SomeTask()
              >>With New SomeOtherProces sor
              >>Try
              >>.SomeOtherTas k()
              >>Catch ex As Exception
              >>Throw
              >>End Try
              >>End With
              >>End Sub
              >>End Class
              >>Class SomeOtherProces sor
              >>>
              >>Sub SomeOtherTask()
              >>>
              >>Try
              >>Dim Status As String = "This operation was successful"
              >>Catch ex As Exception
              >>Throw
              >>End Try
              >>End Sub
              >>End Class
              >>>

              Comment

              • pamelafluente@libero.it

                #8
                Re: Bubbling a status message to the UI

                Thank you Ghost! Now I see what you meant.

                Thanks you very much for taking the time to make this example.

                Well, what to say? I am very grateful. I just hoped there was some way
                easier to maintain.

                It's strange that for errors there is a simple device (exceptions),
                while to bubble a simple
                message we have to go through all this !

                -P


                ps
                boo :)

                GhostInAK ha scritto:
                Hello pamela,
                >
                public class Form1
                >
                private sub Button_click( ... )
                >
                Dim tSomeTask as SomeProcessor = New SomeProcessor
                AddHandler tSomeTask.Statu sChange, addressof StatusChangeHan dler
                >
                tSomeTask.Dance MonkeyDance
                >
                end sub
                >
                private sub StatusChangeHan dler(byval tStatus as string)
                >
                textbox1.text = tstatus
                >
                end sub
                >
                end class
                >
                >
                >
                public class SomeProcessor
                >
                public event StatusChange(by val tStatus as string)
                >
                private withevents tSomeOtherProce ssor as SomeProcessor2 = New SomeProcessor2
                >
                private sub StatusChangeHan dler(byval tStatus as string) handles tSomeOtherProce ssor.StatusChan ge
                raiseevent StatusChange(tS tatus)
                end sub
                >
                public sub DanceMonkeyDanc e()
                tSomeOtherProce ssor.DoSomethin g
                end Sub
                >
                end class
                >
                >
                >
                public class SomeOtherProces sor2
                >
                public event StatusChange(by val tStatus as string)
                >
                public sub DoSomething
                ' Change the status.. look at the perdy percolating..
                raiseevent StatusChange("W as that good for you?")
                end sub
                >
                end class
                >
                Hi Ghost,

                can you make more precise what you mean. Are you talking about a
                shared event?

                Actually the idea of an additional argument does not make me
                enthusiastic,
                but also the idea of some shared event is quite disgusting (to me).
                Could you clarify your suggestion, by applying that to my simple
                example?

                -P

                GhostInAK ha scritto:
                Hello pamela,
                >
                I don't like tomb's solution. You should never pass in an object
                that listens for changes. I would suggest simply raising an event
                from within your processor.
                >
                -Boo
                >
                >Hi guys,
                >>
                >After the Exception question, I have another one, strictly related.
                >I would also like what is your preferred device
                >to bubble a message (not by exception) to the user Interface.
                >Assume for instance the following simple schema. What is the best
                >way
                >to bubble the "Status" string message to the UI ? Please suggest
                >appropriate
                >code changes.
                >I guess that different programmers might have different ideas on how
                >to
                >that
                >in the most flexible way ...
                >-P
                >'--------------------------------- SAMPLE CODE
                >-----------------------
                >>
                >Public Class Form1
                >>
                >Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
                >System.EventAr gs) Handles Button1.Click
                >>
                >Try
                >With New SomeProcessor
                >.SomeTask()
                >' I want for instance the "Status" issued by SomeOtherTask
                >' to be appended to a TextBox on this User Interface
                >' What's the best way to bubble the message here
                >End With
                >Catch ex As Exception
                >Me.RichTextBox 1.AppendText(ex .Message)
                >End Try
                >End Sub
                >End Class
                >>
                >'The following is in separate files
                >>
                >Class SomeProcessor
                >>
                >Sub SomeTask()
                >With New SomeOtherProces sor
                >Try
                >.SomeOtherTask ()
                >Catch ex As Exception
                >Throw
                >End Try
                >End With
                >End Sub
                >End Class
                >Class SomeOtherProces sor
                >>
                >Sub SomeOtherTask()
                >>
                >Try
                >Dim Status As String = "This operation was successful"
                >Catch ex As Exception
                >Throw
                >End Try
                >End Sub
                >End Class
                >>

                Comment

                • GhostInAK

                  #9
                  Re: Bubbling a status message to the UI

                  Hello pamelafluente@l ibero.it,

                  Not so strange. The scenarios which require such a mechanism are fairly few.

                  In addition to the event solution, you may wish to explore the use of MSMQ
                  (MS Message Queue). I don't know your architecture, but if the status generation
                  is burried very deep then MSMQ may be a good solution.

                  You could also look into custom window messages (in the WM_APP range). This
                  would not transfer between web/winforms though.

                  Back on the event solution. You could implement a class from which all your
                  objects inherited. This base class would define the events. You could then
                  devise a mechanism, using reflection, which automajikly wired up the events
                  to be bubbled. *shrug*

                  Good luck.

                  -Boo
                  Thank you Ghost! Now I see what you meant.
                  >
                  Thanks you very much for taking the time to make this example.
                  >
                  Well, what to say? I am very grateful. I just hoped there was some way
                  easier to maintain.
                  >
                  It's strange that for errors there is a simple device (exceptions),
                  while to bubble a simple
                  message we have to go through all this !
                  -P
                  >
                  ps
                  boo :)
                  GhostInAK ha scritto:
                  >
                  >Hello pamela,
                  >>
                  >public class Form1
                  >>
                  >private sub Button_click( ... )
                  >>
                  >Dim tSomeTask as SomeProcessor = New SomeProcessor AddHandler
                  >tSomeTask.Stat usChange, addressof StatusChangeHan dler
                  >>
                  >tSomeTask.Danc eMonkeyDance
                  >>
                  >end sub
                  >>
                  >private sub StatusChangeHan dler(byval tStatus as string)
                  >>
                  >textbox1.tex t = tstatus
                  >>
                  >end sub
                  >>
                  >end class
                  >>
                  >public class SomeProcessor
                  >>
                  >public event StatusChange(by val tStatus as string)
                  >>
                  >private withevents tSomeOtherProce ssor as SomeProcessor2 = New
                  >SomeProcesso r2
                  >>
                  >private sub StatusChangeHan dler(byval tStatus as string) handles
                  >tSomeOtherProc essor.StatusCha nge
                  >raiseevent StatusChange(tS tatus)
                  >end sub
                  >public sub DanceMonkeyDanc e()
                  >tSomeOtherProc essor.DoSomethi ng
                  >end Sub
                  >end class
                  >>
                  >public class SomeOtherProces sor2
                  >>
                  >public event StatusChange(by val tStatus as string)
                  >>
                  >public sub DoSomething
                  >' Change the status.. look at the perdy percolating..
                  >raiseevent StatusChange("W as that good for you?")
                  >end sub
                  >end class
                  >>
                  >>Hi Ghost,
                  >>>
                  >>can you make more precise what you mean. Are you talking about a
                  >>shared event?
                  >>>
                  >>Actually the idea of an additional argument does not make me
                  >>enthusiasti c,
                  >>but also the idea of some shared event is quite disgusting (to me).
                  >>Could you clarify your suggestion, by applying that to my simple
                  >>example?
                  >>-P
                  >>>
                  >>GhostInAK ha scritto:
                  >>>
                  >>>Hello pamela,
                  >>>>
                  >>>I don't like tomb's solution. You should never pass in an object
                  >>>that listens for changes. I would suggest simply raising an event
                  >>>from within your processor.
                  >>>>
                  >>>-Boo
                  >>>>
                  >>>>Hi guys,
                  >>>>>
                  >>>>After the Exception question, I have another one, strictly
                  >>>>related.
                  >>>>I would also like what is your preferred device
                  >>>>to bubble a message (not by exception) to the user Interface.
                  >>>>Assume for instance the following simple schema. What is the best
                  >>>>way
                  >>>>to bubble the "Status" string message to the UI ? Please suggest
                  >>>>appropria te
                  >>>>code changes.
                  >>>>I guess that different programmers might have different ideas on
                  >>>>how
                  >>>>to
                  >>>>that
                  >>>>in the most flexible way ...
                  >>>>-P
                  >>>>'--------------------------------- SAMPLE CODE
                  >>>>-----------------------
                  >>>>Public Class Form1
                  >>>>>
                  >>>>Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
                  >>>>As System.EventArg s) Handles Button1.Click
                  >>>>>
                  >>>>Try
                  >>>>With New SomeProcessor
                  >>>>.SomeTask ()
                  >>>>' I want for instance the "Status" issued by SomeOtherTask
                  >>>>' to be appended to a TextBox on this User Interface
                  >>>>' What's the best way to bubble the message here
                  >>>>End With
                  >>>>Catch ex As Exception
                  >>>>Me.RichText Box1.AppendText (ex.Message)
                  >>>>End Try
                  >>>>End Sub
                  >>>>End Class
                  >>>>'The following is in separate files
                  >>>>>
                  >>>>Class SomeProcessor
                  >>>>>
                  >>>>Sub SomeTask()
                  >>>>With New SomeOtherProces sor
                  >>>>Try
                  >>>>.SomeOtherT ask()
                  >>>>Catch ex As Exception
                  >>>>Throw
                  >>>>End Try
                  >>>>End With
                  >>>>End Sub
                  >>>>End Class
                  >>>>Class SomeOtherProces sor
                  >>>>Sub SomeOtherTask()
                  >>>>>
                  >>>>Try
                  >>>>Dim Status As String = "This operation was successful"
                  >>>>Catch ex As Exception
                  >>>>Throw
                  >>>>End Try
                  >>>>End Sub
                  >>>>End Class

                  Comment

                  • pamelafluente@libero.it

                    #10
                    Re: Bubbling a status message to the UI

                    Looks like I have quite some material to think about.

                    Thank you Ghost. Very helpful. :)

                    -P

                    GhostInAK ha scritto:

                    Not so strange. The scenarios which require such a mechanism are fairly few.
                    >
                    In addition to the event solution, you may wish to explore the use of MSMQ
                    (MS Message Queue). I don't know your architecture, but if the status generation
                    is burried very deep then MSMQ may be a good solution.
                    >
                    You could also look into custom window messages (in the WM_APP range). This
                    would not transfer between web/winforms though.
                    >
                    Back on the event solution. You could implement a class from which all your
                    objects inherited. This base class would define the events. You could then
                    devise a mechanism, using reflection, which automajikly wired up the events
                    to be bubbled. *shrug*
                    >
                    Good luck.
                    >
                    -Boo
                    >
                    Thank you Ghost! Now I see what you meant.

                    Thanks you very much for taking the time to make this example.

                    Well, what to say? I am very grateful. I just hoped there was some way
                    easier to maintain.

                    It's strange that for errors there is a simple device (exceptions),
                    while to bubble a simple
                    message we have to go through all this !
                    -P

                    ps
                    boo :)
                    GhostInAK ha scritto:
                    Hello pamela,
                    >
                    public class Form1
                    >
                    private sub Button_click( ... )
                    >
                    Dim tSomeTask as SomeProcessor = New SomeProcessor AddHandler
                    tSomeTask.Statu sChange, addressof StatusChangeHan dler
                    >
                    tSomeTask.Dance MonkeyDance
                    >
                    end sub
                    >
                    private sub StatusChangeHan dler(byval tStatus as string)
                    >
                    textbox1.text = tstatus
                    >
                    end sub
                    >
                    end class
                    >
                    public class SomeProcessor
                    >
                    public event StatusChange(by val tStatus as string)
                    >
                    private withevents tSomeOtherProce ssor as SomeProcessor2 = New
                    SomeProcessor2
                    >
                    private sub StatusChangeHan dler(byval tStatus as string) handles
                    tSomeOtherProce ssor.StatusChan ge
                    raiseevent StatusChange(tS tatus)
                    end sub
                    public sub DanceMonkeyDanc e()
                    tSomeOtherProce ssor.DoSomethin g
                    end Sub
                    end class
                    >
                    public class SomeOtherProces sor2
                    >
                    public event StatusChange(by val tStatus as string)
                    >
                    public sub DoSomething
                    ' Change the status.. look at the perdy percolating..
                    raiseevent StatusChange("W as that good for you?")
                    end sub
                    end class
                    >
                    >Hi Ghost,
                    >>
                    >can you make more precise what you mean. Are you talking about a
                    >shared event?
                    >>
                    >Actually the idea of an additional argument does not make me
                    >enthusiastic ,
                    >but also the idea of some shared event is quite disgusting (to me).
                    >Could you clarify your suggestion, by applying that to my simple
                    >example?
                    >-P
                    >>
                    >GhostInAK ha scritto:
                    >>
                    >>Hello pamela,
                    >>>
                    >>I don't like tomb's solution. You should never pass in an object
                    >>that listens for changes. I would suggest simply raising an event
                    >>from within your processor.
                    >>>
                    >>-Boo
                    >>>
                    >>>Hi guys,
                    >>>>
                    >>>After the Exception question, I have another one, strictly
                    >>>related.
                    >>>I would also like what is your preferred device
                    >>>to bubble a message (not by exception) to the user Interface.
                    >>>Assume for instance the following simple schema. What is the best
                    >>>way
                    >>>to bubble the "Status" string message to the UI ? Please suggest
                    >>>appropriat e
                    >>>code changes.
                    >>>I guess that different programmers might have different ideas on
                    >>>how
                    >>>to
                    >>>that
                    >>>in the most flexible way ...
                    >>>-P
                    >>>'--------------------------------- SAMPLE CODE
                    >>>-----------------------
                    >>>Public Class Form1
                    >>>>
                    >>>Private Sub Button1_Click(B yVal sender As System.Object, ByVal e
                    >>>As System.EventArg s) Handles Button1.Click
                    >>>>
                    >>>Try
                    >>>With New SomeProcessor
                    >>>.SomeTask( )
                    >>>' I want for instance the "Status" issued by SomeOtherTask
                    >>>' to be appended to a TextBox on this User Interface
                    >>>' What's the best way to bubble the message here
                    >>>End With
                    >>>Catch ex As Exception
                    >>>Me.RichTextB ox1.AppendText( ex.Message)
                    >>>End Try
                    >>>End Sub
                    >>>End Class
                    >>>'The following is in separate files
                    >>>>
                    >>>Class SomeProcessor
                    >>>>
                    >>>Sub SomeTask()
                    >>>With New SomeOtherProces sor
                    >>>Try
                    >>>.SomeOtherTa sk()
                    >>>Catch ex As Exception
                    >>>Throw
                    >>>End Try
                    >>>End With
                    >>>End Sub
                    >>>End Class
                    >>>Class SomeOtherProces sor
                    >>>Sub SomeOtherTask()
                    >>>>
                    >>>Try
                    >>>Dim Status As String = "This operation was successful"
                    >>>Catch ex As Exception
                    >>>Throw
                    >>>End Try
                    >>>End Sub
                    >>>End Class

                    Comment

                    Working...