[gbrainy] Desconnect events when not needed



commit 1849aa628b0dcf0cea60932188ab324fed59e112
Author: Jordi Mas <jmas softcatala org>
Date:   Sun May 8 10:08:43 2011 +0200

    Desconnect events when not needed

 src/Clients/Classical/gbrainy.cs |    5 +++++
 src/Core/Main/GameSession.cs     |   10 ++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index 2adcc11..062e43c 100644
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -379,6 +379,11 @@ namespace gbrainy.Clients.Classical
 		{
 			UpdateSolution (String.Empty, GameDrawingArea.SolutionType.None);
 			UpdateQuestion (String.Empty);
+
+			if (session.CurrentGame != null) {
+				session.CurrentGame.AnswerEvent -= OnAnswerFromGame;
+			}
+
 			session.NextGame ();
 			session.CurrentGame.AnswerEvent += OnAnswerFromGame;
 
diff --git a/src/Core/Main/GameSession.cs b/src/Core/Main/GameSession.cs
index 07cfbb1..f9a8066 100644
--- a/src/Core/Main/GameSession.cs
+++ b/src/Core/Main/GameSession.cs
@@ -234,8 +234,11 @@ namespace gbrainy.Core.Main
 			// Making a deep copy of GameSessionHistory type (base class) for serialization
 			player_history.SaveGameSession (history.Copy ());
 
-			if (CurrentGame != null)
+			if (CurrentGame != null) {
+				CurrentGame.DrawRequest -= GameDrawRequest;
+				CurrentGame.UpdateUIElement -= GameUpdateUIElement;
 				CurrentGame.Finish ();
+			}
 
 			EnableTimer = false;
 			timer.SynchronizingObject = null;
@@ -249,8 +252,11 @@ namespace gbrainy.Core.Main
 		{
 			try
 			{
-				if (CurrentGame != null)
+				if (CurrentGame != null) {
+					CurrentGame.DrawRequest -= GameDrawRequest;
+					CurrentGame.UpdateUIElement -= GameUpdateUIElement;
 					CurrentGame.Finish ();
+				}
 
 				history.GamesPlayed++;
 				CurrentGame = game_manager.GetPuzzle ();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]