diff --git a/PushSharp.Core/ServiceBroker.cs b/PushSharp.Core/ServiceBroker.cs index 4b87f7b1..c5c681d1 100644 --- a/PushSharp.Core/ServiceBroker.cs +++ b/PushSharp.Core/ServiceBroker.cs @@ -179,6 +179,9 @@ public void Start () // Let's wait for the continuation not the task itself toSend.Add (cont); + + // release references to completed tasks + toSend.RemoveAll(task => task.IsCompleted); } if (toSend.Count <= 0) diff --git a/PushSharp.Tests/BrokerTests.cs b/PushSharp.Tests/BrokerTests.cs index 92308707..8074e785 100644 --- a/PushSharp.Tests/BrokerTests.cs +++ b/PushSharp.Tests/BrokerTests.cs @@ -22,13 +22,21 @@ public void Broker_Send_Many () var succeeded = 0; var failed = 0; var attempted = 0; - + var locker = new object(); + var broker = new TestServiceBroker (); broker.OnNotificationFailed += (notification, exception) => { - failed++; + lock (locker) + { + failed++; + } }; - broker.OnNotificationSucceeded += (notification) => { - succeeded++; + broker.OnNotificationSucceeded += (notification) => + { + lock (locker) + { + succeeded++; + } }; broker.Start (); broker.ChangeScale (1); @@ -38,10 +46,10 @@ public void Broker_Send_Many () for (int i = 1; i <= 1000; i++) { attempted++; broker.QueueNotification (new TestNotification { TestId = i }); - } - + } + broker.Stop (); - + c.StopAndLog ("Test Took {0} ms"); Assert.AreEqual (attempted, succeeded);