469,609 Members | 2,251 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Is RaiseEvent Synchronous or Asynchronous in VB .Net ??

Al
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

Nov 20 '05 #1
3 5577

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.
Nov 20 '05 #2
* "=?Utf-8?B?QWw=?=" <Al@discussions.microsoft.com> scripsit:
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.


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/>
Nov 20 '05 #3
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.ComponentModel.CancelEventHandler)

Something like:

Public Class GetDataEventArgs
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
GetDataEventArgs)

Public Class MyProcess

Public Event GetData As GetDataHandler

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

Public Sub Process()
Dim e As New GetDataEventArgs
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:BD**********************************@microsof t.com...
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

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Chris | last post: by
15 posts views Thread by Javier Estrada | last post: by
1 post views Thread by Alexander Kaplunov | last post: by
3 posts views Thread by Pro1712 | last post: by
2 posts views Thread by Gary Wessle | last post: by
reply views Thread by Solution2021 | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.