How to allow for multiple popups at once in WinRT?

后端 未结 2 1046
南旧
南旧 2020-12-06 03:42

If you call the ShowAsync command on a MessageDialog object when another MessageDialog object has already been displayed to the user b

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-06 04:41

    You can easy do it with this extension method:

    public static class MessageDialogShower
    {
        private static SemaphoreSlim _semaphore;
    
        static MessageDialogShower()
        {
            _semaphore = new SemaphoreSlim(1);
        }
    
        public static async Task ShowDialogSafely(this MessageDialog dialog)
        {
            await _semaphore.WaitAsync();
            var result = await dialog.ShowAsync();
            _semaphore.Release();
            return result;
        }
    }
    

提交回复
热议问题