gpt4 book ai didi

c# - Windows 窗体 - 打开新线程时如何防止 System.AccessViolationException

转载 作者:太空宇宙 更新时间:2023-11-03 14:39:32 24 4
gpt4 key购买 nike

我希望这个问题对某些人来说是显而易见的 😊 我有一个 Windows 窗体应用程序,它在单独的子窗体上执行一些独立的进程。它有一个首先打开的主窗体,然后它根据每个子窗体的“事件”数据库值打开子窗体。此过程经常按预期运行数小时而没有任何问题……必要时打开和关闭。我无法弄清楚的问题是应用程序只是卡住,必须手动关闭并重新启动,当然,当它不运行时,它会完全停止处理。

Windows 应用程序错误日志中始终有 2 个错误。第一个是“.Net 运行时”,第二个是“应用程序错误”。第三个信息条目似乎在应用程序重新启动时被记录,但不能 100% 确定它是否在重新启动之前存在。

MainForm 使用不同版本在新线程中打开不同的子表单:

try
{
Thread CS = new Thread(new ThreadStart(CS_Start));
CS.SetApartmentState(ApartmentState.STA);
CS.Start();
}
catch { }

这是在打开子表单之一的新线程中调用的代码......

private void CS_Start ()
{
try
{
using (CS_Searches CS_SearchForm = new CS_Searches())
{
if (!CS_SearchForm.Visible)
CS_SearchForm.ShowDialog();
}
}
catch { }
}

MainForm 打开了 5 个单独的窗体。每个表单都执行完全独立的任务,并且还会根据“处于事件状态”值使用以下方法关闭自身:this.Dispose();

问题似乎总是发生在不同的 CS.Start();线。我曾 try catch 错误,但不幸的是它从未遇到此代码。我还通过添加 using 语句修改了 CS_Start。不幸的是,我一直无法复制这个问题,因为它运行得很好,直到它没有运行,而且频率可能遍布整个 map 。根据我所有的谷歌搜索,它似乎是内存访问冲突,但我没有运气确认这一点或找到修复方法。如有任何帮助,我们将不胜感激。

谢谢,格雷格

这些是错误日志的详细信息:

错误 - .Net 运行时

Application: OA.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Reflection.TargetInvocationException
Stack:
at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(System.Object, System.Object[], System.Object[])
at System.Delegate.DynamicInvokeImpl(System.Object[])
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
at System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
at System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)
at System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
at System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
at System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window)
at OA.MainForm.CS_Start()
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()

错误 - 应用程序错误

Faulting application name: OA.exe, version: 1.0.0.0, time stamp: 0x5d7835c6
Faulting module name: KERNELBASE.dll, version: 6.1.7601.18015, time stamp: 0x50b8479b
Exception code: 0xe0434352
Fault offset: 0x0000000000009e5d
Faulting process id: 0xed0
Faulting application start time: 0x01d5683c859e21b3
Faulting application path: C:\! OA\OA.exe
Faulting module path: C:\Windows\system32\KERNELBASE.dll
Report Id: f77be558-d4a1-11e9-a767-00505691533d

信息 - Windows 错误报告

Fault bucket , type 0
Event Name: CLR20r3
Response: Not available
Cab Id: 0

Problem signature:
P1: OA.exe
P2: 1.0.0.0
P3: 5d793cd6
P4: System.Windows.Forms
P5: 4.0.30319.17929
P6: 4ffa5c0e
P7: 4cba
P8: 27
P9: System.AccessViolationException
P10:

Attached files:

These files may be available here:
C:\Users\AUTO.WERHQ\AppData\Local\Microsoft\Windows\WER\ReportArchive\AppCrash_oa_c95e0af449b9b5070e88c537a95b8ce90dee049_25993682

Analysis symbol:
Rechecking for solution: 0
Report Id: bbe1964a-d56f-11e9-a767-00505691533d
Report Status: 0

信息 - Windows 错误报告 - 报告文件以上内容

Version=1
EventType=CLR20r3
EventTime=132127743632961454
ReportType=2
Consent=1
ReportIdentifier=d5c9cb47-d56e-11e9-a767-00505691533d
IntegratorReportIdentifier=d5c9cb46-d56e-11e9-a767-00505691533d
Response.type=4
Sig[0].Name=Problem Signature 01
Sig[0].Value=OA.exe
Sig[1].Name=Problem Signature 02
Sig[1].Value=1.0.0.0
Sig[2].Name=Problem Signature 03
Sig[2].Value=5d793cd6
Sig[3].Name=Problem Signature 04
Sig[3].Value=System.Windows.Forms
Sig[4].Name=Problem Signature 05
Sig[4].Value=4.0.30319.17929
Sig[5].Name=Problem Signature 06
Sig[5].Value=4ffa5c0e
Sig[6].Name=Problem Signature 07
Sig[6].Value=4cba
Sig[7].Name=Problem Signature 08
Sig[7].Value=27
Sig[8].Name=Problem Signature 09
Sig[8].Value=System.AccessViolationException
DynamicSig[1].Name=OS Version
DynamicSig[1].Value=6.1.7601.2.1.0.256.48
DynamicSig[2].Name=Locale ID
DynamicSig[2].Value=1033
DynamicSig[22].Name=Additional Information 1
DynamicSig[22].Value=276c
DynamicSig[23].Name=Additional Information 2
DynamicSig[23].Value=276cb04a1eafd1e19b2fc54286fd4e13
DynamicSig[24].Name=Additional Information 3
DynamicSig[24].Value=b00b
DynamicSig[25].Name=Additional Information 4
DynamicSig[25].Value=b00bccb4ee23035129f9f2009e37821c
UI[2]=C:\! OA\OA.exe
UI[3]=OA has stopped working
UI[4]=Windows can check online for a solution to the problem.
UI[5]=Check online for a solution and close the program
UI[6]=Check online for a solution later and close the program
UI[7]=Close the program
LoadedModule[0]=C:\! OA\OA.exe
LoadedModule[1]=C:\Windows\SYSTEM32\ntdll.dll
LoadedModule[2]=C:\Windows\SYSTEM32\MSCOREE.DLL
LoadedModule[3]=C:\Windows\system32\KERNEL32.dll
LoadedModule[4]=C:\Windows\system32\KERNELBASE.dll
LoadedModule[5]=C:\Windows\system32\ADVAPI32.dll
LoadedModule[6]=C:\Windows\system32\msvcrt.dll
LoadedModule[7]=C:\Windows\SYSTEM32\sechost.dll
LoadedModule[8]=C:\Windows\system32\RPCRT4.dll
LoadedModule[9]=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscoreei.dll
LoadedModule[10]=C:\Windows\system32\SHLWAPI.dll
LoadedModule[11]=C:\Windows\system32\GDI32.dll
LoadedModule[12]=C:\Windows\system32\USER32.dll
LoadedModule[13]=C:\Windows\system32\LPK.dll
LoadedModule[14]=C:\Windows\system32\USP10.dll
LoadedModule[15]=C:\Windows\system32\IMM32.DLL
LoadedModule[16]=C:\Windows\system32\MSCTF.dll
LoadedModule[17]=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
LoadedModule[18]=C:\Windows\system32\MSVCR110_CLR0400.dll
LoadedModule[19]=C:\Windows\assembly\NativeImages_v4.0.30319_64\mscorlib\9da5bb33cd1c34b7851c088f0cf749cc\mscorlib.ni.dll
LoadedModule[20]=C:\Windows\system32\ole32.dll
LoadedModule[21]=C:\Windows\system32\CRYPTBASE.dll
LoadedModule[22]=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clrjit.dll
LoadedModule[23]=C:\Windows\system32\OLEAUT32.dll
LoadedModule[24]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System\d191674dfd2e0fb89abf108445359453\System.ni.dll
LoadedModule[25]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Drawing\fe0b5caab219a62708e42ad3ab7f0440\System.Drawing.ni.dll
LoadedModule[26]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Windows.Forms\3fac3f0dccd0fdc80be79bd7fcf2261a\System.Windows.Forms.ni.dll
LoadedModule[27]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Configuration\3dd1bdef318925394a5f51fb254b7004\System.Configuration.ni.dll
LoadedModule[28]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Core\8ae856324ba290331c8d1442b3321a22\System.Core.ni.dll
LoadedModule[29]=C:\Windows\assembly\NativeImages_v4.0.30319_64\Microsoft.CSharp\fc2e811c0a4fbcb589f7775a25c7377a\Microsoft.CSharp.ni.dll
LoadedModule[30]=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\nlssorting.dll
LoadedModule[31]=C:\Windows\system32\CRYPTSP.dll
LoadedModule[32]=C:\Windows\system32\rsaenh.dll
LoadedModule[33]=C:\Windows\system32\uxtheme.dll
LoadedModule[34]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Xml\7a54d4ebaa554c877a48c06148506a0e\System.Xml.ni.dll
LoadedModule[35]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Runteb92aa12#\29ffe930d3112e330be0c61b4f83bf5a\System.Runtime.Serialization.ni.dll
LoadedModule[36]=C:\Windows\system32\ws2_32.dll
LoadedModule[37]=C:\Windows\system32\NSI.dll
LoadedModule[38]=C:\Windows\system32\mswsock.dll
LoadedModule[39]=C:\Windows\System32\wshtcpip.dll
LoadedModule[40]=C:\Windows\System32\wship6.dll
LoadedModule[41]=C:\Windows\system32\NLAapi.dll
LoadedModule[42]=C:\Windows\system32\napinsp.dll
LoadedModule[43]=C:\Windows\system32\pnrpnsp.dll
LoadedModule[44]=C:\Windows\system32\DNSAPI.dll
LoadedModule[45]=C:\Windows\System32\winrnr.dll
LoadedModule[46]=C:\Windows\system32\IPHLPAPI.DLL
LoadedModule[47]=C:\Windows\system32\WINNSI.DLL
LoadedModule[48]=C:\Windows\system32\rasadhlp.dll
LoadedModule[49]=C:\Windows\System32\fwpuclnt.dll
LoadedModule[50]=C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.17514_none_a4d6a923711520a9\comctl32.dll
LoadedModule[51]=C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_fa396087175ac9ac\comctl32.dll
LoadedModule[52]=C:\Windows\WinSxS\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.17825_none_2b253c8271ec7765\gdiplus.dll
LoadedModule[53]=C:\Windows\system32\wininet.dll
LoadedModule[54]=C:\Windows\system32\api-ms-win-downlevel-user32-l1-1-0.dll
LoadedModule[55]=C:\Windows\system32\api-ms-win-downlevel-shlwapi-l1-1-0.dll
LoadedModule[56]=C:\Windows\system32\api-ms-win-downlevel-version-l1-1-0.dll
LoadedModule[57]=C:\Windows\system32\version.DLL
LoadedModule[58]=C:\Windows\system32\api-ms-win-downlevel-normaliz-l1-1-0.dll
LoadedModule[59]=C:\Windows\system32\normaliz.DLL
LoadedModule[60]=C:\Windows\system32\iertutil.dll
LoadedModule[61]=C:\Windows\system32\api-ms-win-downlevel-advapi32-l1-1-0.dll
LoadedModule[62]=C:\Windows\system32\USERENV.dll
LoadedModule[63]=C:\Windows\system32\profapi.dll
LoadedModule[64]=C:\Windows\system32\Secur32.dll
LoadedModule[65]=C:\Windows\system32\SSPICLI.DLL
LoadedModule[66]=C:\Windows\system32\SHELL32.dll
LoadedModule[67]=C:\Windows\system32\api-ms-win-downlevel-advapi32-l2-1-0.dll
LoadedModule[68]=C:\Windows\system32\api-ms-win-downlevel-ole32-l1-1-0.dll
LoadedModule[69]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.ServiceModel\b6c60909860ace07b6b6617c71d089ff\System.ServiceModel.ni.dll
LoadedModule[70]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Servd1dec626#\ca7c2fd7257e0452df4a39ec969e8913\System.ServiceModel.Internals.ni.dll
LoadedModule[71]=C:\Windows\assembly\NativeImages_v4.0.30319_64\SMDiagnostics\7ce23442406c8bff478964ae214251b5\SMDiagnostics.ni.dll
LoadedModule[72]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Serv30e99c02#\fe0b22eaecf87715a043c1c76884bae6\System.ServiceModel.Channels.ni.dll
LoadedModule[73]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Servf73e6522#\0e0f2d16bef2c0e1dd62edff4b3cf02c\System.ServiceModel.Web.ni.dll
LoadedModule[74]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.IdentityModel\7b2df4768784cae3f8714f1ececbe25a\System.IdentityModel.ni.dll
LoadedModule[75]=C:\Windows\assembly\NativeImages_v4.0.30319_64\System.Net.Http\8653972f8d9923f44566604ae0de1aea\System.Net.Http.ni.dll
LoadedModule[76]=C:\Windows\system32\rasapi32.dll
LoadedModule[77]=C:\Windows\system32\rasman.dll
LoadedModule[78]=C:\Windows\system32\rtutils.dll
LoadedModule[79]=C:\Windows\system32\winhttp.dll
LoadedModule[80]=C:\Windows\system32\webio.dll
LoadedModule[81]=C:\Windows\system32\credssp.dll
LoadedModule[82]=C:\Windows\system32\dhcpcsvc6.DLL
LoadedModule[83]=C:\Windows\system32\dhcpcsvc.DLL
LoadedModule[84]=C:\Windows\system32\CFGMGR32.dll
LoadedModule[85]=C:\Windows\system32\RpcRtRemote.dll
LoadedModule[86]=C:\Windows\system32\WindowsCodecs.dll
LoadedModule[87]=C:\! OA\OpenPop.dll
LoadedModule[88]=C:\Windows\system32\bcrypt.dll
LoadedModule[89]=C:\Windows\system32\CLBCatQ.DLL
LoadedModule[90]=C:\Windows\System32\ieframe.dll
LoadedModule[91]=C:\Windows\System32\api-ms-win-downlevel-shell32-l1-1-0.dll
LoadedModule[92]=C:\Windows\system32\SXS.DLL
LoadedModule[93]=C:\Windows\system32\api-ms-win-downlevel-shlwapi-l2-1-0.dll
LoadedModule[94]=C:\Windows\system32\PROPSYS.dll
LoadedModule[95]=C:\Windows\system32\apphelp.dll
LoadedModule[96]=C:\Windows\system32\urlmon.dll
LoadedModule[97]=C:\Windows\system32\CRYPT32.dll
LoadedModule[98]=C:\Windows\system32\MSASN1.dll
LoadedModule[99]=C:\Windows\system32\MSHTML.dll
LoadedModule[100]=C:\Windows\System32\netprofm.dll
LoadedModule[101]=C:\Windows\System32\npmproxy.dll
LoadedModule[102]=C:\Windows\system32\schannel.DLL
LoadedModule[103]=C:\Windows\system32\ncrypt.dll
LoadedModule[104]=C:\Windows\system32\bcryptprimitives.dll
LoadedModule[105]=C:\Windows\system32\WINTRUST.dll
LoadedModule[106]=C:\Windows\system32\GPAPI.dll
LoadedModule[107]=C:\Windows\system32\cryptnet.dll
LoadedModule[108]=C:\Windows\system32\WLDAP32.dll
LoadedModule[109]=C:\Windows\system32\SensApi.dll
LoadedModule[110]=C:\Windows\system32\MLANG.dll
LoadedModule[111]=C:\Windows\System32\jscript9.dll
LoadedModule[112]=C:\Windows\system32\msimtf.dll
LoadedModule[113]=C:\Windows\system32\d2d1.dll
LoadedModule[114]=C:\Windows\system32\DWrite.dll
LoadedModule[115]=C:\Windows\system32\dxgi.dll
LoadedModule[116]=C:\Windows\system32\dwmapi.dll
LoadedModule[117]=C:\Windows\system32\d3d11.dll
LoadedModule[118]=C:\Windows\system32\D3D10Warp.dll
LoadedModule[119]=C:\Windows\system32\WINMM.dll
LoadedModule[120]=C:\Windows\system32\MMDevAPI.DLL
LoadedModule[121]=C:\Windows\system32\ntmarta.dll
LoadedModule[122]=C:\Windows\system32\SETUPAPI.dll
LoadedModule[123]=C:\Windows\system32\DEVOBJ.dll
LoadedModule[124]=C:\Windows\system32\OLEACC.DLL
LoadedModule[125]=C:\Windows\system32\uiautomationcore.dll
LoadedModule[126]=C:\Windows\system32\PSAPI.DLL
LoadedModule[127]=C:\Windows\system32\ImgUtil.dll
LoadedModule[128]=C:\Program Files\Internet Explorer\ieproxy.dll
LoadedModule[129]=C:\Windows\System32\UIAnimation.dll
LoadedModule[130]=C:\Windows\system32\T2EMBED.DLL
LoadedModule[131]=C:\Windows\System32\msxml3.dll
LoadedModule[132]=C:\Windows\system32\XmlLite.dll
LoadedModule[133]=C:\Windows\Microsoft.NET\Framework64\v4.0.30319\diasymreader.dll
FriendlyEventName=Stopped working
ConsentKey=CLR20r3
AppName=OA
AppPath=C:\! OA\OA.exe

最佳答案

这真的很有趣 - 您可以制作转储并使用 WInDbg 探索它们。但我会考虑创建与 Console Application 相同的应用程序并探索其行为。结果可能是某种 GUI 相关的错误/功能,您达到了处理程序/GDI 限制或类似的东西。

关于c# - Windows 窗体 - 打开新线程时如何防止 System.AccessViolationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57913159/

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