p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning Visual C# 2005 (http://p2p.wrox.com/forumdisplay.php?f=222)
-   -   Ch13CardLib time of execution event handler (http://p2p.wrox.com/showthread.php?t=64534)

jeroen1980 December 12th, 2007 09:01 AM

Ch13CardLib time of execution event handler
I am studying the code of the CardLib that raises the LastCardDrawn event (page 380 in the book) and I have the following question about the code:
Why can you assume that the line: "return cards[cardNum]" is executed BEFORE the method that subscribed to the LastCardDrawn event (in this case the Reshuffle() method). Is it possible that the Reshuffle method is called BEFORE the return statement (maybe only if there would be a lot more code to process in the GetCard method after raising the event "holding up" the return statement) and so the card returned by the GetCard method is the last card of the shuffled deck instead of the last card of the original deck?
Isn't it safer to first store the last card in a local variable, then raise the event (triggering the Reshuffle() method) and then return the local variable containing the last card?

All times are GMT -4. The time now is 08:26 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.