apple push notification with APNS sharp

Nnp picture Nnp · Jul 2, 2010 · Viewed 10.4k times · Source

i use APNS Sharp library for my apple push notification. i have downloded from Here.i use sample test program provided by APNS sharp library without any modification.
it simply does not send any notification until i put break point at that line of code. if i put break point. i just work fine.is this expected behaviour or i am doing something wrong. and also i am not getting any exception. thanks for any help. here is the code

static void Main(string[] args)
{
    bool sandbox = true;
    string testDeviceToken = "Token";
    string p12File = "apn_developer_identity.p12";
    string p12FilePassword = "yourpassword";
    int sleepBetweenNotifications = 15000;
    string p12Filename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File);
    NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword, 1);
    service.SendRetries = 5; 
    service.ReconnectDelay = 5000; //5 seconds
    service.Error += new NotificationService.OnError(service_Error);
    service.NotificationTooLong += new NotificationService.OnNotificationTooLong(service_NotificationTooLong);
    service.BadDeviceToken += new NotificationService.OnBadDeviceToken(service_BadDeviceToken);
    service.NotificationFailed += new NotificationService.OnNotificationFailed(service_NotificationFailed);
    service.NotificationSuccess += new NotificationService.OnNotificationSuccess(service_NotificationSuccess);
    service.Connecting += new NotificationService.OnConnecting(service_Connecting);
    service.Connected += new NotificationService.OnConnected(service_Connected);
    service.Disconnected += new NotificationService.OnDisconnected(service_Disconnected);
    Notification alertNotification = new Notification(testDeviceToken);
    alertNotification.Payload.Alert.Body = "Testing {0}...";
    alertNotification.Payload.Sound = "default";
    alertNotification.Payload.Badge = i;
    if (service.QueueNotification(alertNotification))
      Console.WriteLine("Notification Queued!");
    else
      Console.WriteLine("Notification Failed to be Queued!");
    Console.WriteLine("Cleaning Up...");

    service.Close();// if i dont put a break point in here, it simply does not send any notification

    service.Dispose();

}

i hope my question is clear...
Update: i am stuck here.please any one can help me.

Answer

Nnp picture Nnp · Jul 11, 2010

i found out the problem. it was error in APNS SHARP library thread workflow.

EDIT:
i am calling this method after queueing all the notification.
like
service.start();
and here is method

     public void Send()
    {
        foreach (NotificationConnection conn in this.notificationConnections)
        {
           // Console.Write("Start Sending");
            conn.start(P12File, P12FilePassword);
        }
    }