Export to GitHub

apns-sharp - issue #22

service.close stack my program


Posted on Mar 3, 2010 by Grumpy Lion

What steps will reproduce the problem? 1. using Notifications 2. when running the program it is send to my device the notifications but stack forever on the line service.close()

Comment #1

Posted on Mar 22, 2010 by Swift Horse

Yes, I am experiencing the same problem. I can kill the service with Dispose(), but would rather close properly.

Comment #2

Posted on Mar 27, 2010 by Happy Lion

I'm not able to reproduce this here. If you look at the code, .Close() in NotificationConnection is not much different than Dispose. It just lets all the notifications be sent out before closing things up.

I suggest calling .Close() and then .Dispose() on the NotificationService in that order.

Are you saying that .Close() never finishes? I don't see any reason why it would not finish unless you keep queuing more notifications. Make sure your code stops queuing notifications before you call Close.

Comment #3

Posted on Apr 6, 2010 by Happy Camel

The workerThread's workerMethod() loops while !disposed. This flag is not set until Dispose(); however, the Close() method attempts to Join() with the worker thread before Dispose() is ever called.

changing Line 344 of NotificationConnection.cs to [while (!disposing && !closing)] lets the workerThread know it needs to stop looping.

Comment #4

Posted on Apr 6, 2010 by Happy Lion

@bruce.weber

Do you have the latest SVN source?

Your line 344 does not match up, so I suspect you might have an older version.

Anyways, there's only two loops in the workerMethod that would be causing the workerThread to not die:

NotificationConnection.cs:352 -> while(!disposing && !closing) This should abort just fine if .Close() is called

NotificationConnection.cs:356 -> while(this.notifications.Count > 0 && !disposing) This may take awhile to actually complete, but eventually notifications.Count will reach 0 as the next line is this.notifications.Dequeue() and a notification is only attempted to be sent as long as it hasn't been sent successfully, or it's been tried this.SendRetries number of times. I can't see how this loop would be causing issues either.

I'm guessing this is a non-issue and has been fixed since whatever version others who are experiencing this are using.

Comment #5

Posted on Apr 6, 2010 by Happy Lion

Quick update, I took a look at the revision history, and if you look at NotificationConnection.cs in revision 18, line 344 (which you refer to) is "while (!disposing)". In revision 19, line 344 changes to: "while (!disposing && !closing)" which is your suggested fix.

So, please update your source code to the latest version.

Here are the revision details for 19: http://code.google.com/p/apns-sharp/source/detail?r=19

Comment #6

Posted on Sep 2, 2010 by Helpful Horse

I am getting the same problem with service.close() method. It is never ending. But my code is updated, I use "while (!disposing && !closing)" in NotificationConnection.cs. It just get stuck at "workerThread.Join();" at 286 line.

Status: Invalid

Labels:
Type-Defect Priority-Medium