WinRT - MessageDialog.ShowAsync will throw UnauthorizedAccessException in my custom class

后端 未结 4 773
花落未央
花落未央 2021-01-11 14:41

I Want to write my own control, when the ctor is invoked, a MessageBox is shown.

public class Class1
{
    public Class1()
    {
        ShowDialog();
    }
         


        
4条回答
  •  迷失自我
    2021-01-11 15:11

    I think I've found it. I had the same problem when creating messageboxes in any other threads besides the main thread. This is the C++ solution but I think you can convert it easily ;)

        IAsyncOperation ^Op = msgbox->ShowAsync();
        task( Op ).then([=](IUICommand^ C)
        {
    
        }).then([](task t) 
            {
                try 
                {
                    t.get();
                }
                catch (Platform::Exception ^e)
                {   
                    //ERROR!                            
                }           
            });
    

    On a side note this is the correct way to handle ANY WinRT/Windows 8 Store C++ exception.

提交回复
热议问题