前提・実現したいこと・試したこと
クラスを作っているのですが、上のコードのように public NotificationScheduler(略) とするとその中にawaitを入れられず、下のコードのように public async void Scheduler(略) とするとほかの場所から NotificationScheduler notificationScheduler = new NotificationScheduler(略) のようにして使う(?)ことができないです。awaitを使う方法または、classの中のpublic async voidをほかの場所から使う方法を教えてください。
該当のソースコード
C#
1namespace Example.Helpers 2{ 3 public class NotificationScheduler 4 { 5 public NotificationScheduler(string title, string folder, DateTime notificationDateTime, string dateTimeText, int iD) //ここ 6 { 7 string snoozeText = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView().GetString("NotificationScheduler_Snooze"); 8 var content = new ToastContentBuilder() 9 .AddArgument(title, iD) 10 .AddText(title) 11 .AddText(dateTimeText) 12 .AddText(folder) 13 .AddButton(new ToastButton() 14 { 15 ActivationType = ToastActivationType.Background, 16 ActivationOptions = new ToastActivationOptions() 17 { 18 AfterActivationBehavior = ToastAfterActivationBehavior.PendingUpdate 19 } 20 } 21 .AddArgument(iD.ToString(), "Snooze") 22 .SetContent(snoozeText) 23 ) 24 .SetToastScenario(ToastScenario.Reminder) 25 .AddCustomTimeStamp(notificationDateTime) 26 .GetToastContent(); 27 28 ScheduledToastNotification scheduledToast = new ScheduledToastNotification(content.GetXml(), DateTimeOffset.Now.AddSeconds(10)); 29 30 var notifier = await ToastNotificationManager.GetDefault().GetToastNotifierForToastCollectionIdAsync("MyToastCollection"); //ここ 31 32 notifier.AddToSchedule(scheduledToast); 33 } 34 } 35} 36
C#
1namespace Example.Helpers 2{ 3 public class NotificationScheduler 4 { 5 public async void Scheduler(string title, string folder, DateTime notificationDateTime, string dateTimeText, int iD) //ここ 6 { 7 string snoozeText = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView().GetString("NotificationScheduler_Snooze"); 8 var content = new ToastContentBuilder() 9 .AddArgument(title, iD) 10 .AddText(title) 11 .AddText(dateTimeText) 12 .AddText(folder) 13 .AddButton(new ToastButton() 14 { 15 ActivationType = ToastActivationType.Background, 16 ActivationOptions = new ToastActivationOptions() 17 { 18 AfterActivationBehavior = ToastAfterActivationBehavior.PendingUpdate 19 } 20 } 21 .AddArgument(iD.ToString(), "Snooze") 22 .SetContent(snoozeText) 23 ) 24 .SetToastScenario(ToastScenario.Reminder) 25 .AddCustomTimeStamp(notificationDateTime) 26 .GetToastContent(); 27 28 ScheduledToastNotification scheduledToast = new ScheduledToastNotification(content.GetXml(), DateTimeOffset.Now.AddSeconds(10)); 29 30 var notifier = await ToastNotificationManager.GetDefault().GetToastNotifierForToastCollectionIdAsync("MyToastCollection"); //ここ 31 32 notifier.AddToSchedule(scheduledToast); 33 } 34 } 35} 36
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2022/09/26 22:23
2022/09/26 22:42
退会済みユーザー
2022/09/26 22:51
2022/09/27 03:44