首页 > 系统相关 >WPF System.Windows.MessageBox.Show Dispatcher processing has been suspended, but messages are still

WPF System.Windows.MessageBox.Show Dispatcher processing has been suspended, but messages are still

时间:2024-09-22 17:23:47浏览次数:11  
标签:IntPtr MessageBox Int32 selectedBks Show Windows System Dispatcher

 private void SelectedCommandExecuted(object obj)
 {
     if (obj != null && obj is DataGrid dg)
     {
         if (dg != null)
         {
             var selectedBks = dg.SelectedItems;
             if (selectedBks != null && selectedBks.Count > 0)
             {
                 MessageBox.Show($"Selected {selectedBks.Count} Items",
                     "Multi Select", MessageBoxButton.OK);
             }
         }
     }
 }

 

 

 

 

The detailed exception as below.

System.InvalidOperationException
  HResult=0x80131509
  Message=Dispatcher processing has been suspended, but messages are still being processed.
  Source=WindowsBase
  StackTrace:
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.MessageBox(HandleRef hWnd, String text, String caption, Int32 type)
   at System.Windows.MessageBox.ShowCore(IntPtr owner, String messageBoxText, String caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult, MessageBoxOptions options)
   at System.Windows.MessageBox.Show(String messageBoxText, String caption, MessageBoxButton button)

 

 

The therapy is to use Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>{}) as below

private void SelectedCommandExecuted(object obj)
{
    Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() =>
    {
        if (obj != null && obj is DataGrid dg)
        {
            if (dg != null)
            {
                var selectedBks = dg.SelectedItems;
                if (selectedBks != null && selectedBks.Count > 0)
                {
                    MessageBox.Show($"Selected {selectedBks.Count} Items",
                        "Multi Select", MessageBoxButton.OK);
                }
            }
        }
    }));
}

 

标签:IntPtr,MessageBox,Int32,selectedBks,Show,Windows,System,Dispatcher
From: https://www.cnblogs.com/Fred1987/p/18425558

相关文章

  • 不小心把Windows资源管理器关闭了怎么办
    因为在压缩文件夹的时候Windows资源管理器给卡死了,怎么都关不了所以进行了一个很降智的操作...打开任务管理器,把Windows资源管理器给“结束任务”了...一瞬间,电脑开始闪屏,然后最底下那条任务栏菜单全部消失不见,按windows键都没反应...幸亏浏览器界面还在,赶紧搜索怎么恢复当意......
  • windows源码ReadFile函数的实现
    windows源码ReadFile函数的实现windows源码ReadFile函数的实现文章目录windows源码ReadFile函数的实现ReadFileReadFileBOOLWINAPIReadFile(HANDLEhFile,LPVOIDlpBuffer,DWORDnNumberOfBytesToRead,LPDWORDlpNumberOfBytesRead,L......
  • windows应急响应(二)
    1.启动项win+r输入msconfig,在"工具"里找到“任务管理器”;(底部任务栏右键,也可打开),查看启动项一般应用启动项位置:C:\Users\adnim\AppData\Roaming\Microsoft\Windows\StartMenu\Programs\Startupwin+r输入msinfo32,在"软件环境"里可以看到Autoruns功能强大,会自动......
  • 维持访问技战术-Windows
    粘滞键后们粘滞键(StickyKeys)是Windows操作系统中的一个辅助功能,它允许用户通过连续按下键盘上的Shift、Ctrl、Alt或Windows徽标键两次来激活这些键的持续按下状态,这样用户就可以用单手操作键盘。然而,这个功能有时会被恶意软件或黑课利用来绕过登录屏幕,实现所谓的“粘滞键后们”。......
  • WPF Combobox switch up and down then show the big picture in the right part
    <ComboBoxx:Name="cbx"Grid.Row="0"Grid.Column="0"SelectedIndex="0"ItemsSource="{StaticResourcebooksData}"FontSize="20"......
  • WPF Combobox show Image and textblock via DataTemplate
    <ComboBoxGrid.Row="0"Grid.Column="0"SelectedIndex="0"ItemsSource="{StaticResourcebooksData}"FontSize="20"Foreground=&quo......
  • 基于windows的mysql5.7安装配置教程
    目录0.写在前面的话1.下载安装包2.进行目录选择和解压操作3.配置环境变量4.创建my.ini文件5.管理员运行终端6.安装mysqld7.初始化数据库8.启动mysql服务9.进入mysql管理终端10.修改root密码11.刷新权限12.注销内容13.重启mysql14.输入密码测试15.我的总结0......
  • WPF Canvas show custom control with ellipse filled with image and text,peridoica
    //customcontrol<UserControlx:Class="WpfApp389.ElpImageTbk"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"......
  • 雨晨26120.1843 Windows 11 IOT LTSC2024 IE 极简版
    文件:YC24H2_26120.1843_IoTltsc2024_lite_install.wim大小:1735369862字节修改时间:2024年9月21日,星期六,13:28:39MD5:45A8652ACF59A422301DC4742518A4E2SHA1:324CC1052E0CF22DCC42FBFA230246FAD0CFFF15CRC32:86AA5FA8https://www.123pan.com/s/zEbRVv-9nd8?......
  • WINDOWS安装RAGFLOW完整流程
    RAGFLOW是比较强大的知识库,支持搜索,聊天多种模式。知识库相比anyllm,fastgpt,dify,maxkb更强大,支持自定义分隔符,支持各种大模型提供商,如ollama等。官方体验地址,RAGFlow1:虚拟机安装:不建议通过wsl安装,wsl会遇到systecmctl不可用等诸多问题。以VMWarePro为例,参考下面链接完成安装......