w250697116 / apns-sharp

Automatically exported from code.google.com/p/apns-sharp
0 stars 0 forks source link

Notification wont be sent unless thread sleeps after sending it #34

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Fairly simple to reproduce, just replace the counter value to 1 in the
NotificationTest distributed with the source, and you will be able to see
this problem.

I tested this on a desktop computer with dsl connection to the internet.

Original issue reported on code.google.com by mutchin...@gmail.com on 1 Jun 2010 at 11:52

GoogleCodeExporter commented 8 years ago
Hey, nevermind, it was a case of closing the service before the connection was 
even
open. Sorry for the fake issue.

Original comment by mutchin...@gmail.com on 1 Jun 2010 at 11:59

GoogleCodeExporter commented 8 years ago
No worries.

Original comment by jond...@gmail.com on 2 Jun 2010 at 2:30

GoogleCodeExporter commented 8 years ago
I have this issue also... calling service.Close(); does not wait for any queued 
notifications to be sent. This appears to only happen on the FIRST send of the 
application.

I've had to move service.Close(); to service_NotificationSuccess, although this 
doesn't really make sense if multiple messages are being sent.

To replicate: change the loop in JdSoft.Apple.Apns.Test.Program to 
for (int i = 1; i <= 1; i++)
Comment the following line: 
System.Threading.Thread.Sleep(sleepBetweenNotifications);

Original comment by krtr...@gmail.com on 18 Jun 2010 at 8:35

GoogleCodeExporter commented 8 years ago
To me, it appears a "correct" fix can be added in 
JdSoft.Apple.Apns.Notifications.NotificationConnection on line 280.

Current code:
Thread.Sleep(250);

Fix:
while (notifications.Count > 0)
{
    Thread.Sleep(250);
}

A helpful comment on that line says
// 250 ms should be ample time for the loop to dequeue any remaining 
notifications

It appears 250ms might be marginally too small an amount, on average my system 
is taking 500 ms to dequeue the notifications, thought this loop should take 
care of it.

Original comment by krtr...@gmail.com on 18 Jun 2010 at 8:51

GoogleCodeExporter commented 8 years ago
I've changed the code to:

int slept = 0; 
int maxSleep = 10000; //10 seconds

while (notifications.Count > 0 && slept++ <= maxSleep)
    Thread.Sleep(100);

This should be a safe way to wait until all are dequeued

Original comment by jond...@gmail.com on 21 Jun 2010 at 3:58

GoogleCodeExporter commented 8 years ago
Looks like a good check, though I believe maxSleep should be divided by 100 
since the thread is sleeping (if the desired max is 10000ms).

int slept = 0; 
int maxSleep = 10000; //10 seconds

while (notifications.Count > 0 && slept++ <= (maxSleep / 100))
    Thread.Sleep(100);

Original comment by krtr...@gmail.com on 21 Jun 2010 at 4:45

GoogleCodeExporter commented 8 years ago
Ahh yes, thanks for catching that...

Original comment by jond...@gmail.com on 21 Jun 2010 at 4:48

GoogleCodeExporter commented 8 years ago
Thank you, it helps me too. I receive nothing when I try only one 
notification... after following your instructions it works fine!

Original comment by nes...@ingens-networks.com on 27 Aug 2010 at 8:53