Home All Groups Group Topic Archive Search About

Bubbling a status message to the UI

Author
24 Sep 2006 3:48 PM
pamelafluente
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(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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 SomeOtherProcessor
            Try
                .SomeOtherTask()
            Catch ex As Exception
                Throw
            End Try

        End With
    End Sub

End Class


Class SomeOtherProcessor

    Sub SomeOtherTask()

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

    End Sub

End Class

Author
24 Sep 2006 4:09 PM
tomb
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

pamelaflue***@libero.it wrote:

Show quoteHide quote
>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(ByVal sender As System.Object, ByVal e As
>System.EventArgs) 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 SomeOtherProcessor
>            Try
>                .SomeOtherTask()
>            Catch ex As Exception
>                Throw
>            End Try
>
>        End With
>    End Sub
>
>End Class
>
>
>Class SomeOtherProcessor
>
>    Sub SomeOtherTask()
>
>        Try
>            Dim Status As String = "This operation was successful"
>        Catch ex As Exception
>            Throw
>        End Try
>
>    End Sub
>
>End Class
>

>
Author
24 Sep 2006 4:33 PM
pamelafluente
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:

Show quoteHide quote
> 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
>
> pamelaflue***@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
> >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(ByVal sender As System.Object, ByVal e As
> >System.EventArgs) 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 SomeOtherProcessor
> >            Try
> >                .SomeOtherTask()
> >            Catch ex As Exception
> >                Throw
> >            End Try
> >
> >        End With
> >    End Sub
> >
> >End Class
> >
> >
> >Class SomeOtherProcessor
> >
> >    Sub SomeOtherTask()
> >
> >        Try
> >            Dim Status As String = "This operation was successful"
> >        Catch ex As Exception
> >            Throw
> >        End Try
> >
> >    End Sub
> >
> >End Class
> >
> > 
> >
Author
24 Sep 2006 8:51 PM
tomb
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


pamelaflue***@libero.it wrote:

Show quoteHide quote
>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
>>
>>pamelaflue***@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
>>>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(ByVal sender As System.Object, ByVal e As
>>>System.EventArgs) 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 SomeOtherProcessor
>>>           Try
>>>               .SomeOtherTask()
>>>           Catch ex As Exception
>>>               Throw
>>>           End Try
>>>
>>>       End With
>>>   End Sub
>>>
>>>End Class
>>>
>>>
>>>Class SomeOtherProcessor
>>>
>>>   Sub SomeOtherTask()
>>>
>>>       Try
>>>           Dim Status As String = "This operation was successful"
>>>       Catch ex As Exception
>>>           Throw
>>>       End Try
>>>
>>>   End Sub
>>>
>>>End Class
>>>
>>>
>>>
>>>     
>>>
>

>
Author
24 Sep 2006 10:55 PM
GhostInAK
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

Show quoteHide quote
> 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(ByVal sender As System.Object, ByVal e
> As System.EventArgs) 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 SomeOtherProcessor
> Try
> .SomeOtherTask()
> Catch ex As Exception
> Throw
> End Try
> End With
> End Sub
> End Class
>
> Class SomeOtherProcessor
>
> Sub SomeOtherTask()
>
> Try
> Dim Status As String = "This operation was successful"
> Catch ex As Exception
> Throw
> End Try
> End Sub
>
> End Class
>
Author
25 Sep 2006 7:34 AM
pamelafluente
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:

Show quoteHide quote
> 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(ByVal sender As System.Object, ByVal e
> > As System.EventArgs) 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 SomeOtherProcessor
> > Try
> > .SomeOtherTask()
> > Catch ex As Exception
> > Throw
> > End Try
> > End With
> > End Sub
> > End Class
> >
> > Class SomeOtherProcessor
> >
> > Sub SomeOtherTask()
> >
> > Try
> > Dim Status As String = "This operation was successful"
> > Catch ex As Exception
> > Throw
> > End Try
> > End Sub
> >
> > End Class
> >
Author
25 Sep 2006 5:58 PM
GhostInAK
Hello pamela,

public class Form1

private sub Button_click( ... )

Dim tSomeTask as SomeProcessor = New SomeProcessor
AddHandler tSomeTask.StatusChange, addressof StatusChangeHandler

tSomeTask.DanceMonkeyDance

end sub

private sub StatusChangeHandler(byval tStatus as string)

textbox1.text = tstatus

end sub

end class



public class SomeProcessor

public event StatusChange(byval tStatus as string)

private withevents tSomeOtherProcessor as SomeProcessor2 = New SomeProcessor2

private sub StatusChangeHandler(byval tStatus as string) handles tSomeOtherProcessor.StatusChange
raiseevent StatusChange(tStatus)
end sub

public sub DanceMonkeyDance()
tSomeOtherProcessor.DoSomething
end Sub

end class



public class SomeOtherProcessor2

public event StatusChange(byval tStatus as string)

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

end class

Show quoteHide quote
> 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(ByVal sender As System.Object, ByVal e As
>>> System.EventArgs) 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 SomeOtherProcessor
>>> Try
>>> .SomeOtherTask()
>>> Catch ex As Exception
>>> Throw
>>> End Try
>>> End With
>>> End Sub
>>> End Class
>>> Class SomeOtherProcessor
>>>
>>> Sub SomeOtherTask()
>>>
>>> Try
>>> Dim Status As String = "This operation was successful"
>>> Catch ex As Exception
>>> Throw
>>> End Try
>>> End Sub
>>> End Class
>>>
Author
25 Sep 2006 6:53 PM
pamelafluente
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:

Show quoteHide quote
> Hello pamela,
>
> public class Form1
>
> private sub Button_click( ... )
>
> Dim tSomeTask as SomeProcessor = New SomeProcessor
> AddHandler tSomeTask.StatusChange, addressof StatusChangeHandler
>
> tSomeTask.DanceMonkeyDance
>
> end sub
>
> private sub StatusChangeHandler(byval tStatus as string)
>
> textbox1.text = tstatus
>
> end sub
>
> end class
>
>
>
> public class SomeProcessor
>
> public event StatusChange(byval tStatus as string)
>
> private withevents tSomeOtherProcessor as SomeProcessor2 = New SomeProcessor2
>
> private sub StatusChangeHandler(byval tStatus as string) handles tSomeOtherProcessor.StatusChange
> raiseevent StatusChange(tStatus)
> end sub
>
> public sub DanceMonkeyDance()
> tSomeOtherProcessor.DoSomething
> end Sub
>
> end class
>
>
>
> public class SomeOtherProcessor2
>
> public event StatusChange(byval tStatus as string)
>
> public sub DoSomething
>     '  Change the status.. look at the perdy percolating..
>     raiseevent StatusChange("Was 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(ByVal sender As System.Object, ByVal e As
> >>> System.EventArgs) 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 SomeOtherProcessor
> >>> Try
> >>> .SomeOtherTask()
> >>> Catch ex As Exception
> >>> Throw
> >>> End Try
> >>> End With
> >>> End Sub
> >>> End Class
> >>> Class SomeOtherProcessor
> >>>
> >>> Sub SomeOtherTask()
> >>>
> >>> Try
> >>> Dim Status As String = "This operation was successful"
> >>> Catch ex As Exception
> >>> Throw
> >>> End Try
> >>> End Sub
> >>> End Class
> >>>
Author
26 Sep 2006 3:15 AM
GhostInAK
Hello pamelaflue***@libero.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

Show quoteHide quote
> 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.StatusChange, addressof StatusChangeHandler
>>
>> tSomeTask.DanceMonkeyDance
>>
>> end sub
>>
>> private sub StatusChangeHandler(byval tStatus as string)
>>
>> textbox1.text = tstatus
>>
>> end sub
>>
>> end class
>>
>> public class SomeProcessor
>>
>> public event StatusChange(byval tStatus as string)
>>
>> private withevents tSomeOtherProcessor as SomeProcessor2 = New
>> SomeProcessor2
>>
>> private sub StatusChangeHandler(byval tStatus as string) handles
>> tSomeOtherProcessor.StatusChange
>> raiseevent StatusChange(tStatus)
>> end sub
>> public sub DanceMonkeyDance()
>> tSomeOtherProcessor.DoSomething
>> end Sub
>> end class
>>
>> public class SomeOtherProcessor2
>>
>> public event StatusChange(byval tStatus as string)
>>
>> public sub DoSomething
>> '  Change the status.. look at the perdy percolating..
>> raiseevent StatusChange("Was 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(ByVal sender As System.Object, ByVal e
>>>>> As System.EventArgs) 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 SomeOtherProcessor
>>>>> Try
>>>>> .SomeOtherTask()
>>>>> Catch ex As Exception
>>>>> Throw
>>>>> End Try
>>>>> End With
>>>>> End Sub
>>>>> End Class
>>>>> Class SomeOtherProcessor
>>>>> Sub SomeOtherTask()
>>>>>
>>>>> Try
>>>>> Dim Status As String = "This operation was successful"
>>>>> Catch ex As Exception
>>>>> Throw
>>>>> End Try
>>>>> End Sub
>>>>> End Class
Author
26 Sep 2006 9:56 AM
pamelafluente
Looks like I have quite some material to think about.

Thank you Ghost. Very helpful.  :)

-P

GhostInAK ha scritto:


Show quoteHide quote
> 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.StatusChange, addressof StatusChangeHandler
> >>
> >> tSomeTask.DanceMonkeyDance
> >>
> >> end sub
> >>
> >> private sub StatusChangeHandler(byval tStatus as string)
> >>
> >> textbox1.text = tstatus
> >>
> >> end sub
> >>
> >> end class
> >>
> >> public class SomeProcessor
> >>
> >> public event StatusChange(byval tStatus as string)
> >>
> >> private withevents tSomeOtherProcessor as SomeProcessor2 = New
> >> SomeProcessor2
> >>
> >> private sub StatusChangeHandler(byval tStatus as string) handles
> >> tSomeOtherProcessor.StatusChange
> >> raiseevent StatusChange(tStatus)
> >> end sub
> >> public sub DanceMonkeyDance()
> >> tSomeOtherProcessor.DoSomething
> >> end Sub
> >> end class
> >>
> >> public class SomeOtherProcessor2
> >>
> >> public event StatusChange(byval tStatus as string)
> >>
> >> public sub DoSomething
> >> '  Change the status.. look at the perdy percolating..
> >> raiseevent StatusChange("Was 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(ByVal sender As System.Object, ByVal e
> >>>>> As System.EventArgs) 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 SomeOtherProcessor
> >>>>> Try
> >>>>> .SomeOtherTask()
> >>>>> Catch ex As Exception
> >>>>> Throw
> >>>>> End Try
> >>>>> End With
> >>>>> End Sub
> >>>>> End Class
> >>>>> Class SomeOtherProcessor
> >>>>> Sub SomeOtherTask()
> >>>>>
> >>>>> Try
> >>>>> Dim Status As String = "This operation was successful"
> >>>>> Catch ex As Exception
> >>>>> Throw
> >>>>> End Try
> >>>>> End Sub
> >>>>> End Class