base.Show()抛出InvalidOperationException

我遇到了base.Show()抛出InvalidOperationException的问题。 这有几个问题:

  • 只有当我在Debug - > Exceptions菜单中显示“Common Language Runtime Exceptions”时,该错误才会显示在vs2012中,但如果我没有运行它,则不会显示该错误。
  • 当在vs2012之外运行程序时,消息框会显示错误,并显示此帖子底部显示的堆栈跟踪。
  • 我试图研究在base.Show()上抛出的InvalidOperationException异常,但是在找到与base.Show()相关的任何东西时都没有成功。
  • 程序正在做的是打开一个表单,当单击一个链接时,它将使用以下代码打开一个DocViewer窗口:

     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 ORDERtCATEGORY", 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方法添加到主窗口类中。 这应该解决之前发生的线程问题。 现在发生的唯一问题应该更容易解决,即修复base.Show()方法抛出InvalidOperationException错误。 用于的类不允许使用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;
                }
            }
        }
    }
    

    在base.Show()调用之前,我可以通过将下面的代码添加到Show方法来解决问题:

    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
    
    链接地址: http://www.djcxy.com/p/62945.html

    上一篇: base.Show() throwing InvalidOperationException

    下一篇: InvalidOperationException on webservice call with C# client and Java server side