Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 版本中存在Threadstateexception,但未调试_C#_Debugging_Release_Thread State - Fatal编程技术网

C# 版本中存在Threadstateexception,但未调试

C# 版本中存在Threadstateexception,但未调试,c#,debugging,release,thread-state,C#,Debugging,Release,Thread State,每当我试图打开一个文件对话框时,我都会得到未处理的threadstateexception。 我只有在使用发布设置运行VisualStudio(2012)时才得到它,当我更改回调试时,一切似乎都按预期工作。 应用程序在最后一行上崩溃,ShowDialog() 我做错了什么?是否存在代码错误,或者VS中是否缺少某些设置 我已经从调试中复制了我正在使用的所有子文件,以便发布它。 我已经尝试过搜索这个问题,但是我的谷歌fu缺少 一些裁剪代码: [STAThread] public static voi

每当我试图打开一个文件对话框时,我都会得到未处理的
threadstateexception。
我只有在使用发布设置运行VisualStudio(2012)时才得到它,当我更改回调试时,一切似乎都按预期工作。
应用程序在最后一行上崩溃,
ShowDialog()

我做错了什么?是否存在代码错误,或者VS中是否缺少某些设置

我已经从调试中复制了我正在使用的所有子文件,以便发布它。 我已经尝试过搜索这个问题,但是我的谷歌fu缺少

一些裁剪代码:

[STAThread]
public static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());
}

public static bool compareListViewWithFile(int listViewIndex)
{
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Filter = "Comma Separated Value files (.csv)|*.csv|All Files (*.*)|*.*";
    openFileDialog1.FilterIndex = 1;

    if (currentListView.Items == null || currentListView.Items.Count == 0)
    {
        openFileDialog1.Title = "Choose first file";
        DialogResult userClickedOK = openFileDialog1.ShowDialog();
        // etc
    }
}

可能您的调试配置也是错误的,这是未定义的行为。添加line
Control.CheckForIllegalCrossThreadCalls=true
到Main函数的开头以检查此项。@Alex我已添加控件。CheckForIllegalCrossThreadCalls=true;大体上,但我看不出有什么不同。