- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我得到这个异常:
Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException was unhandled HResult=-2146232832 Message=An exception 'Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException' occurred Source=Microsoft.VisualStudio.Debugger.Runtime StackTrace: at Microsoft.VisualStudio.Debugger.Runtime.Main.ThrowCrossThreadMessageException(String formatString) InnerException:
当我使用这段代码时:
public string ShowOpenFileDialog(string initialPath, string filter = null)
{
var dialog = new OpenFileDialog()
{
InitialDirectory = Directory.Exists(initialPath) ? Path.GetDirectoryName(initialPath) : String.Empty,
FileName = File.Exists(initialPath) ? Path.GetFileName(initialPath) : String.Empty,
Filter = filter
};
if (dialog.ShowDialog() == true)
{
return dialog.FileName;
}
return String.Empty;
}
我没有明确使用多线程,那么是什么原因造成的呢?它在调试期间经常发生,但不是一直发生。我已经将方法签名更改了大约一百万次,因为我正在传递 ref/out 参数并认为它们可能是原因。
编辑:我从 UI 线程调用它。 View 中的按钮 -> ViewModel 中的命令 -> ShowOpenFileDialog。
最佳答案
虽然我仍然不确定为什么会发生这种情况,但我已经想出如何解决我的问题。我的解决方案中有多个项目,并且配置了两个启动项目(客户端+服务器)。当我通过调试启动两个项目时,调试器似乎有问题。所以我只是关闭了目前最不重要的项目的调试,因此调试器只处理一个项目。
关于c# - CrossThreadMessagingException WPF OpenFileDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21613505/
我有一个简单的代码,可以通过标签组件在我的 GUI 中显示时间序列。此代码位于计时器的滴答事件中。有时,我会收到“Microsoft.VisualStudio.Debugger.Runtime.Cro
我得到这个异常: Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException was unhandled HResult
我有一个正在开发的应用程序,它可以从 ISP(下载配额)中轮询使用情况。我已经尝试通过“new Thread(ThreaProc)”对此进行线程处理,但这没有用,现在正在尝试基于 IAsyncResu
我是一名优秀的程序员,十分优秀!