我正在一个目录Project上工作,在该目录中,当3分钟不使用该程序或空闲该程序时,将显示一个充当待机屏幕的表格,该表格将播放视频(我使用AxWindowsMediaPlayer
)。通过单击表单中的任意位置,待机屏幕将关闭并返回主表单。
该程序运行正常,但有时会在关闭待机屏幕表单期间出现某些情况,应用程序因错误而崩溃:
这是完整的错误详细信息:
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
块中,专门捕获了AccessViolationException
(以前是exception
,但仍然遇到问题):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变量的早期绑定(bind)。请注意,该错误是由于System.Windows.Forms类引起的
尝试:
Dim stndByScreen As Object
stndByScreen = standByScreen
stndByScreen.ShowDialog()
而不是直接使用standByScreen
关于vb.net - AccessViolationException未处理?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22340239/