gpt4 book ai didi

vb.net - AccessViolationException 未处理?

转载 作者:行者123 更新时间:2023-12-03 16:12:52 24 4
gpt4 key购买 nike

我正在处理一个目录项目,当程序没有被使用或空闲 3 分钟时,一个充当 的表单待机屏幕播放视频将显示(我使用 AxWindowsMediaPlayer )。通过单击表单中的任意位置,待机屏幕将关闭并返回主表单。

该程序运行良好,但有时在 关闭期间待机屏幕表单,应用程序崩溃并出现以下错误:

AccessViolationException was unhandled. Attempted to read or write protected memory. This is often an indication that other memory is corrupt.



这是完整的错误细节:
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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com