From f840582c15e64415a3f4f8b301866c8110e58aac Mon Sep 17 00:00:00 2001 From: wulf Date: Mon, 8 Jun 2015 12:04:33 +0800 Subject: [PATCH] on multi-thread the sequential will throw System.ArgumentOutOfRangeException --- .../NotificationService.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/JdSoft.Apple.Apns.Notifications/NotificationService.cs b/JdSoft.Apple.Apns.Notifications/NotificationService.cs index 6cd3844..1385e7a 100644 --- a/JdSoft.Apple.Apns.Notifications/NotificationService.cs +++ b/JdSoft.Apple.Apns.Notifications/NotificationService.cs @@ -467,11 +467,14 @@ void newCon_Connecting(object sender) private bool queueSequential(Notification notification) { - if (sequential > notificationConnections.Count - 1) - sequential = 0; - - if (notificationConnections[sequential] != null) - return notificationConnections[sequential++].QueueNotification(notification); + var index = sequential; + if (index > notificationConnections.Count - 1) + sequential = index = 0; + else + sequential++; + + if (notificationConnections[index] != null) + return notificationConnections[index].QueueNotification(notification); return false; }