Is RaiseEvent Synchronous or Asynchronous in VB .Net ??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Al

    Is RaiseEvent Synchronous or Asynchronous in VB .Net ??

    Hi,

    I believe that when an event is Raised is C#, it is performed synchronously, as a value is returned by the event handler, even if that value is NULL. However, as VB does not have the ability to receive a return value, I was wondering is the call was performed asynchronously, rather than blocking on a call for which it would not receive a response.

    I was specifically thinking of the case of having a cient subscribing to the event in a server, and the server being present in a remote machine.

    Al

  • Mattias Sjögren

    #2
    Re: Is RaiseEvent Synchronous or Asynchronous in VB .Net ??


    Raising an event calls the handlers synchronously, regardless of
    language.



    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Is RaiseEvent Synchronous or Asynchronous in VB .Net ??

      * "=?Utf-8?B?QWw=?=" <Al@discussions .microsoft.com> scripsit:[color=blue]
      > I believe that when an event is Raised is C#, it is performed
      > synchronously, as a value is returned by the event handler, even if that
      > value is NULL. However, as VB does not have the ability to receive a
      > return value, I was wondering is the call was performed asynchronously,
      > rather than blocking on a call for which it would not receive a
      > response.[/color]

      The 'RaiseEvent' statement is processed as a call to the 'Invoke' method
      of the event's delegate. This is a synchronous operation.

      --
      Herfried K. Wagner [MVP]
      <URL:http://dotnet.mvps.org/>

      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Is RaiseEvent Synchronous or Asynchronous in VB .Net ??

        Al,
        In addition to the

        Events in .NET any language are processed synchronously.

        I believe because to be CLS compliant events do not return values, thus VB
        does not allow a return value for an event. Also events by definition are
        multicast, if the event returned a value how would each handler return its
        value where there are more then one handler??

        What I would do is follow the Event Pattern & define my event as a Sub with
        Object & EventArgs parameters and make a custom EventArgs that has the
        "return value" in it. (Similar to the
        System.Componen tModel.CancelEv entHandler)

        Something like:

        Public Class GetDataEventArg s
        Inherits EventArgs

        Private m_data As Integer

        Public Property Data() As Integer
        Get
        Return m_data
        End Get
        Set(ByVal value As Integer)
        m_data = value
        End Set
        End Property

        End Class

        Public Delegate Sub GetDataHandler( ByVal sender As Object, ByVal e As
        GetDataEventArg s)

        Public Class MyProcess

        Public Event GetData As GetDataHandler

        Protected Overridable Sub OnGetData(ByVal e As GetDataEventArg s)
        RaiseEvent GetData(Me, e)
        End Sub

        Public Sub Process()
        Dim e As New GetDataEventArg s
        OnGetData(e)
        If e.Data = 100 Then
        ' do something interesting
        End If
        End Sub

        End Class



        Hope this helps
        Jay

        "Al" <Al@discussions .microsoft.com> wrote in message
        news:BD6F1B55-604C-4967-AE93-09CD1C6F0232@mi crosoft.com...[color=blue]
        > Hi,
        >
        > I believe that when an event is Raised is C#, it is performed[/color]
        synchronously, as a value is returned by the event handler, even if that
        value is NULL. However, as VB does not have the ability to receive a return
        value, I was wondering is the call was performed asynchronously, rather than
        blocking on a call for which it would not receive a response.[color=blue]
        >
        > I was specifically thinking of the case of having a cient subscribing to[/color]
        the event in a server, and the server being present in a remote machine.[color=blue]
        >
        > Al
        >[/color]


        Comment

        Working...