我正在处理一个目录Project,在该目录中,当程序未被使用或闲置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
块中,特别是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
请帮帮我,谢谢
答案 0 :(得分:0)
这可能是由于standByScreen变量的早期绑定造成的。请注意,该错误是由System.Windows.Forms类引起的
尝试:
Dim stndByScreen As Object
stndByScreen = standByScreen
stndByScreen.ShowDialog()
而不是直接使用standByScreen