Vb.net 是否未处理AccessViolationException?

Vb.net 是否未处理AccessViolationException?,vb.net,exception-handling,axwindowsmediaplayer,crash,Vb.net,Exception Handling,Axwindowsmediaplayer,Crash,我正在处理一个目录项目,在这个项目中,当程序在3分钟内未被使用或空闲时,一个用作播放视频的备用屏幕的窗体将显示我使用AxWindowsMediaPlayer。单击表单中的任意位置,备用屏幕将关闭并返回主表单 程序运行正常,但有时在关闭备用屏幕窗体期间,应用程序会崩溃,并出现以下错误: AccessViolationException未处理。试图读或写 受保护的内存。这通常表示其他内存正在使用 腐败 这是完整的错误详细信息: System.AccessViolationException was

我正在处理一个目录项目,在这个项目中,当程序在3分钟内未被使用或空闲时,一个用作播放视频的备用屏幕的窗体将显示我使用AxWindowsMediaPlayer。单击表单中的任意位置,备用屏幕将关闭并返回主表单

程序运行正常,但有时在关闭备用屏幕窗体期间,应用程序会崩溃,并出现以下错误:

AccessViolationException未处理。试图读或写 受保护的内存。这通常表示其他内存正在使用 腐败

这是完整的错误详细信息:

System.AccessViolationException was unhandled
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
  Source=System.Windows.Forms
  StackTrace:
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.RunDialog(Form form)
       at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       at System.Windows.Forms.Form.ShowDialog()
       at BuildingDirectory.main.tmrTime_Tick(Object sender, EventArgs e) in C:\Users\pc\Documents\Visual Studio 2010\Projects\testing\BuildingDirectory\BuildingDirectory\main.vb:line 128
       at System.Windows.Forms.Timer.OnTick(EventArgs e)
       at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at BuildingDirectory.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
奇怪的是,错误指向的代码行被包含在try-catch块中,专门用于捕获AccessViolationExceptionit以前是异常的,但仍然遇到问题:

Private Sub tmrTime_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrTime.Tick
    Try
        lblTime.Text = TimeOfDay
        If standby = 2 Then
            standby += 1
            standByScreen.ShowDialog() ---> this is where the error is pointing to
        Else
            standby += 1
        End If
    Catch ex As AccessViolationException
        MessageBox.Show(ex.ToString)
    End Try
End Sub

请帮助我,谢谢

这可能是由于standByScreen变量的早期绑定。请注意,此错误是由System.Windows.Forms类引起的

尝试:

Dim stndByScreen As Object

stndByScreen = standByScreen
stndByScreen.ShowDialog()

您是否应该在调用ShowDialog之前停止计时器,然后再次启动它,而不是直接使用待机屏幕

?好的,我也将计时器用作时间显示,请参见代码:lblTime.Text=timeofday以获取代码重用。此外,停止计时器也无关紧要,因为即使计时器继续运行,我也有一个条件:如果standby=2,将确保待机屏幕仅在所需的时间显示:但谢谢你的建议。我也有同样的问题。你找到原因了吗?@Evgeny sorry没有找到这个问题的任何原因/解决方案。