我有一个类似于下面的 ASP.NET MVC 控制器方法:
public JsonResult GenerateNotifications()
{
Task.Factory.StartNew(() => MyService.GenerateNotifications());
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
我的服务方法如下所示:
public async void GenerateNotifications()
{
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString(AppHelper.AzureNotificationHubConnectionString, "myhub");
for (int i = 0; i < 10; i++)
{
var notification = new
{
aps = new
{
alert = string.Format("Awesome Notification {0}", i),
sound = "default"
}
};
string notificationJSON = JsonConvert.SerializeObject(notification);
NotificationOutcome result = await hub.SendAppleNativeNotificationAsync(notificationJSON, "mytag");
}
}
我遇到的问题是,在我应该收到的 10 个通知中,我通常只收到 5-6 个。
我处理async
电话的方式有问题吗?
我应该以不同于控制器的方式生成通知吗?