473,322 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How do events fit in?

Will the 2nd line in the following code execute immediately? Or will it
wait until the event handler finishes?

RaiseEvent Closing()
mySocket.Close()
Nov 21 '05 #1
4 1904
it will execute after the event handler is completed. It would only execute
syncronous (at the same time) if it was in a second thread.

"Terry Olsen" <to******@hotmail.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Will the 2nd line in the following code execute immediately? Or will it
wait until the event handler finishes?

RaiseEvent Closing()
mySocket.Close()

Nov 21 '05 #2
Terry,
Have you tried the code?

All the handlers attached to the Closing event will finish running then the
socket itself will be closed. Hence Closing should pass a class derived
from System.ComponentModel.CancelEventArgs so that event handlers have a
chance to cancel closing the

Something like:

Dim e as New CancelEventArgs()
RaiseEvent Closing(me, e)
If e.Cancel Then Exit Sub
mySocket.Close()
RaiseEvent Closed(me, EventArgs.Empty)

Of course the two RaiseEvent statements should be wrapped in protected
overridable On<Event> subs per the "Design Guidelines for Class Library
Developers":

http://msdn.microsoft.com/library/de...Guidelines.asp

http://msdn.microsoft.com/library/de...Guidelines.asp

Note: within VB.NET you can simply use RaiseEvent rather then checking to
see if a delegate variable is Nothing and invoking the delegate variable...

Hope this helps
Jay
"Terry Olsen" <to******@hotmail.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Will the 2nd line in the following code execute immediately? Or will it
wait until the event handler finishes?

RaiseEvent Closing()
mySocket.Close()

Nov 21 '05 #3
Events do not create new threads, they work in the same thread, hence
the next line of code will NOT get executed untill the event handler
finishes.
(but differently when in different threads).

This is a common misconception, that events create their own threads...

Clasperm

"Terry Olsen" <to******@hotmail.com> wrote in message
news:e2**************@TK2MSFTNGP10.phx.gbl...
Will the 2nd line in the following code execute immediately? Or will it
wait until the event handler finishes?

RaiseEvent Closing()
mySocket.Close()

Nov 21 '05 #4
Terry,

Every command in a thread is executed sequentialy there will never be any
overlapping.
(When that was there was making programs would be completly impossible)

In a method it will be done command after command without any interruption
with the exception when you do doevents, wich will than be evaluated.

This does not mean that in the meanwhile another thread (with
multiprocessors parallel or otherwise serial) can do a lot of other things.

I hope this helps?

Cor

"Terry Olsen" <to******@hotmail.com>
...
Will the 2nd line in the following code execute immediately? Or will it
wait until the event handler finishes?

RaiseEvent Closing()
mySocket.Close()

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sasha | last post by:
Hi everyone, Here is my problem: I have the following classes: - DataNode - this class is designed to hold some data and will be contained in a tree like data structure DataTree. When...
6
by: Saso Zagoranski | last post by:
Hi! How can I unregister all the events registered to a control? I have seen a piece of code in another thread, which gets all the registered handlers for a specific event. Let's say I have a...
14
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using...
2
by: Bob Rundle | last post by:
I have the following code, which appears to be working. However it doesn't look right. The part I am wondering about is the logic in DisconnectEvents(). This logic creates a new delegate and...
4
by: LP | last post by:
Hello! I am still transitioning from VB.NET to C#. I undertand the basic concepts of Delegates, more so of Events and somewhat understand AsyncCallback methods. But I need some clarification on...
11
by: Nicky Smith | last post by:
Hello, I'm studying a book on VB.net Win apps, and I'm reading a section on events and delegates and raising events. Is it just me, or is this not just subs dressed up as something else? I...
30
by: Burkhard | last post by:
Hi, I am new to C# (with long year experience in C++) and I am a bit confused by the language construct of events. What is it I can do with events that I cannot do with delegates? At the moment...
5
by: Richard Maher | last post by:
Hi, Here I mean "User" in the Programmer or Javascript sense. I merely wish to programmatically trigger an Event. It would be absolutely fantastic if there was a (Form level?) ONUSEREVENT() and...
14
by: xoozlez | last post by:
Hi there, I have a registration form where I like to filter out the past events of 2007. This is the code I am using : strSQL = "SELECT EventID, EventName, EventDateBegin, EventDateEnd,...
1
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.