【发布时间】:2013-07-31 05:26:58
【问题描述】:
我的代码实现有问题。我目前正在使用 PushSharp 库,我想做的一件事是如果事件触发,我想根据它是什么事件返回一个真值或假值。代码如下:
public static bool SenddNotification()
{
var push = new PushBroker();
//Wire up the events for all the services that the broker registers
push.OnNotificationSent += NotificationSent;
push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
}
static bool DeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, INotification notification)
{
//Currently this event will only ever happen for Android GCM
Console.WriteLine("Device Registration Changed: Old-> " + oldSubscriptionId + " New-> " + newSubscriptionId + " -> " + notification);
return false;
}
static bool NotificationSent(object sender, INotification notification)
{
Console.WriteLine("Sent: " + sender + " -> " + notification);
return true;
}
所以我想要的是如果事件触发,根据发生的情况返回真或假,然后最终在第一个方法中返回这个值
【问题讨论】:
-
那么,这是两种情况之一,还是两种情况都会发生?
-
不应该出现同时触发的情况。
-
我会说创建一个全局布尔值,并在您的事件中返回它,然后在您的第一个方法中返回它。但是,它并不漂亮。
-
老实说,我不知道这意味着什么,我也不知道如何解决这个问题:P 所以......即使它不漂亮!任何帮助都会很好