C# PushSharp-单例与否

C# PushSharp-单例与否,c#,push-notification,pushsharp,C#,Push Notification,Pushsharp,我以前使用过PushSharp v2,但希望更新到v4。我想知道在我的情况下,单身是否真的是最好的做法 当前工作流:我有一个每分钟启动一次的作业,检查是否有新的通知要发送 PushSharp v.4引入了GcmServiceBroker.Start()和GcmServiceBroker.Stop(),我想知道单例是否真的是最佳实践,因为您不能使用Stop()。至少我还没弄明白。我不能使用Stop()的原因是,当我调用Stop()时,它设置了标志IsAddingCompleted,这会阻止更多通知

我以前使用过PushSharp v2,但希望更新到v4。我想知道在我的情况下,单身是否真的是最好的做法

当前工作流:我有一个每分钟启动一次的作业,检查是否有新的通知要发送

PushSharp v.4引入了GcmServiceBroker.Start()和GcmServiceBroker.Stop(),我想知道单例是否真的是最佳实践,因为您不能使用Stop()。至少我还没弄明白。我不能使用Stop()的原因是,当我调用Stop()时,它设置了标志IsAddingCompleted,这会阻止更多通知添加到队列中,我不知道如何释放该锁

因此,我的解决方案是不使用Stop(),但据我所知,Stop()确保在退出之前发送所有通知,我不想放弃这一改进。那么,是否可以使用PushSharp v4“正确的方式”作为单例,还是每次开始作业时创建一个新对象更好

这是我作为单身汉的代码:

public class GcmPushService
{
    static GcmPushService()
    {
        Push = PushBrokerSingleton.Instance;
    }

    internal static GcmServiceBroker Push { get; }

    public static void QueueNotification(string deviceToken, GcmNotification notification)
    {            
        notification.RegistrationIds.Add(deviceToken);
        Push.QueueNotification(notification);           
    }

    private class PushBrokerSingleton
    {            
        static PushBrokerSingleton()
        {
            var gcmServiceBroker = new GcmServiceBroker(...gcmConfiguration);

            //Exception handling

            gcmServiceBroker.Start();

            Instance = gcmServiceBroker;
        }

        internal static readonly GcmServiceBroker Instance;
    }  
}