C# base.Show()引发InvalidOperationException
我在base.Show()引发InvalidOperationException时遇到问题。这有几个问题:C# base.Show()引发InvalidOperationException,c#,.net,winforms,show,invalidoperationexception,C#,.net,Winforms,Show,Invalidoperationexception,我在base.Show()引发InvalidOperationException时遇到问题。这有几个问题: 仅当我在调试->异常菜单中显示“公共语言运行时异常”时,该错误才会在vs2012中显示,但如果我在没有该菜单的情况下运行它,则不会显示该错误 在vs2012之外运行程序时,会显示一个消息框,其中显示错误,堆栈跟踪显示在本文底部 我曾尝试在线研究base.Show()上抛出的InvalidOperationException,但没有找到任何与base.Show()相关的内容 程序正在执行的操
private void paperVisionLink_Click(object sender, RoutedEventArgs e)
{
try
{
AnalRunSeq sequence = (bob.Resources["AnalRunSeqsCollection"] as CollectionViewSource).View.CurrentItem as AnalRunSeq;
if (sequence != null)
{
try
{
var pveView = this.ShowCOCDocumentForWorkorder((sequence.Sample.WorkOrderID));
}
catch (Exception ex)
{
ELI_Data.DataLogger.Logger.Error("Error starting papervision window", ex);
}
}
}
catch
{
MessageBox.Show("Cannot find COC document for that Work Order.");
}
}
public Window ShowCOCDocumentForWorkorder(string workorder)
{
PaperVision pve = new PaperVision("bluser", "bluser");
pve.SubmitSearchCriteria("WORK ORDER\tCATEGORY", workorder.ToUpper() + "\tCOC");
XDocument response = pve.ExecuteQuery();
XElement documentXml = response.Descendants("DOC").FirstOrDefault();
PVEWindow pveView = null;
if (!documentXml.IsNull())
{
pveView = new PVEWindow();
pveView.Show(
string.Format("{0}/HttpInterface.asp", EnergyDatabase.Setup.DocImaging.WebService),
EnergyDatabase.Setup.DocImaging.EntityID.Value,
pve.SessionID,
EnergyDatabase.Setup.DocImaging.DocProjects.Single(dp => dp.Project == "LOGIN").ProjectID.Value,
documentXml.Attribute("DOCID").Value);
}
return pveView;
}
pveView.Show方法是base.Show()方法抛出执行选项的位置:
public void Show(string url, int entityId, string sessionId, int projId, string docId)
{
try
{
base.Show(); //exception thrown here
this.PvdmDocView.InitComm(url, entityId, sessionId, projId, docId);
}
catch (Exception ex)
{
Logger.Error("Error opening papervision viewer", ex);
throw;
}
}
以下是在visual studio之外运行程序时引发的异常:
************** Exception Text **************
System.InvalidOperationException: Dispatcher processing has been suspended, but messages are still being processed.
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, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.UnsafeNativeMethods.CoCreateInstance(Guid& clsid, Object punkOuter, Int32 context, Guid& iid)
at System.Windows.Forms.AxHost.CreateWithoutLicense(Guid clsid)
at System.Windows.Forms.AxHost.CreateWithLicense(String license, Guid clsid)
at System.Windows.Forms.AxHost.CreateInstanceCore(Guid clsid)
at System.Windows.Forms.AxHost.CreateInstance()
at System.Windows.Forms.AxHost.GetOcxCreate()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
最奇怪的是,尽管引发了此异常,但如果在显示消息框后尝试继续,则所有操作都正常运行,因此我不确定如何解决此问题。任何帮助都将不胜感激
编辑
我已经更新了上面的帖子,删除了线程,并将ShowCOCDocumentForWorkorder方法添加到主窗口类中。这将解决以前出现的线程问题。现在发生的唯一更容易解决的问题是修复引发InvalidOperationException错误的base.Show()方法。中使用的类不允许使用Invoke方法,尽管我不确定原因。
以下是PVEWindow类的完整类代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Microbiology
{
using System.Windows.Forms;
/// <summary>
/// Interaction logic for PVEWindow.xaml
/// </summary>
public partial class PVEWindow : Window
{
public PVEWindow()
{
this.InitializeComponent();
base.Show();
}
public void Show(string url, int entityId, string sessionId, int projId, string docId)
{
//base.Show();
try
{
this.PvdmDocView.InitComm(url, entityId, sessionId, projId, docId);
}
catch (Exception ex)
{
ELI_Data.DataLogger.Logger.Error("Error opening papervision viewer", ex);
throw;
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Shapes;
名称空间微生物学
{
使用System.Windows.Forms;
///
///PVEWindow.xaml的交互逻辑
///
公共部分类PVEWindow:窗口
{
公共PVEWindow()
{
this.InitializeComponent();
base.Show();
}
public void Show(字符串url、int-entityId、字符串sessionId、int-projId、字符串docId)
{
//base.Show();
尝试
{
this.PvdmDocView.InitComm(url、entityId、sessionId、projId、docId);
}
捕获(例外情况除外)
{
ELI_Data.DataLogger.Logger.Error(“打开papervision viewer时出错”,ex);
投掷;
}
}
}
}
我能够通过在base.Show()调用之前向Show方法添加以下代码来解决此问题:
我能够通过在base.Show()调用之前向Show方法添加以下代码来解决此问题:
在调用
show()
之前,您的窗口似乎已关闭。检查答案。我已经看了您提到的问题,但无法使用建议的答案。InvokeRequired对我的类不可用,尽管我不确定原因。此外,在调用show之前,窗口不会关闭。pveView.Closed是在使用show()方法的ShowCOCDocumentForWorkorder调用之后调用的。pveView.Closed不是控件(例如表单)吗?如果是这样,Windows可能会终止线程,因此在尝试显示控件之前关闭该控件。是的,PVEWindow是一个32位COM对象。如果是这样,我希望窗口不会显示线程是否被终止,但事实并非如此。抛出错误后,我继续,窗口将显示并正常运行。是否尝试替换base.Show()使用this.Invoke((MethodInvoker)(()=>base.Show()代码>?我确信这与“调用线程无法访问此对象有关,因为另一个线程拥有它”。在调用show()
之前,您的窗口似乎已关闭。检查答案。我已经看了您提到的问题,但无法使用建议的答案。InvokeRequired对我的类不可用,尽管我不确定原因。此外,在调用show之前,窗口不会关闭。pveView.Closed是在使用show()方法的ShowCOCDocumentForWorkorder调用之后调用的。pveView.Closed不是控件(例如表单)吗?如果是这样,Windows可能会终止线程,因此在尝试显示控件之前关闭该控件。是的,PVEWindow是一个32位COM对象。如果是这样,我希望窗口不会显示线程是否被终止,但事实并非如此。抛出错误后,我继续,窗口将显示并正常运行。是否尝试替换base.Show()使用this.Invoke((MethodInvoker)(()=>base.Show()代码>?我确信这与“调用线程无法访问此对象有关,因为另一个线程拥有它”。在调用show()
之前,您的窗口似乎已关闭。检查答案。我已经看了您提到的问题,但无法使用建议的答案。InvokeRequired对我的类不可用,尽管我不确定原因。此外,在调用show之前,窗口不会关闭。pveView.Closed是在使用show()方法的ShowCOCDocumentForWorkorder调用之后调用的。pveView.Closed不是控件(例如表单)吗?如果是这样,Windows可能会终止线程,因此在尝试显示控件之前关闭该控件。是的,PVEWindow是一个32位COM对象。如果是这样,我希望窗口不会显示线程是否被终止,但事实并非如此。抛出错误后,我继续,窗口将显示并正常运行。是否尝试替换base.Show()
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);