C#7の機能を使用できる場合は、それを「破棄」変数に割り当てます。
_ = iPushNotificationService.SendPushNotification(objNotificationMessage);
C#7を使用できない場合は、変数に割り当てることができます。
var t = iPushNotificationService.SendPushNotification(objNotificationMessage);
または、次のような拡張メソッドを使用します。
public static class TaskExtensions {
public static void Ignore(this Task t) {
}
}
その後:
iPushNotificationService.SendPushNotification(objNotificationMessage).Ignore();
結果には興味がないかもしれませんが、少なくともそれをログに記録するために、その通知の送信に失敗した場合は興味があるかもしれないことに注意してください。その場合、次のいずれかを使用できますContinueWith
。
SendNotification().ContinueWith(c =>
{
// do something with c.Exception
}, TaskContinuationOptions.OnlyOnFaulted).Ignore();
または、それを別の非同期メソッドに移動します。
static async void SendNotification() { // if you hate async void - use Task
try {
await iPushNotificationService.SendPushNotification(objNotificationMessage);
}
catch (Exception ex {
// log it
}
}
そしてそれを呼び出します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加