Oht*_*Oht 2 c# controls tcp invoke
在C#/ .net中,当发生错误时,堆栈将记录在Windows错误日志中.但是,我的应用程序有很多跨线程调用.堆栈跟踪似乎在每个Invoke(MarshalledInvoke)停止.
例如:
我的堆栈:
Exception Info: Facebook.FacebookApiException
Stack:
at System.Windows.Forms.Control.MarshaledInvoke(System.Windows.Forms.Control, System.Delegate, System.Object[], Boolean)
at System.Windows.Forms.Control.Invoke(System.Delegate, System.Object[])
at Test.TcpTest.InterpretData()
at Test.TcpTest.Incoming(System.String)
at Test.TcpTest.cLoop()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
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()
Run Code Online (Sandbox Code Playgroud)
在堆栈中进一步执行的代码中发生异常.但是,堆栈每次都停在marshalledInvoke.
有什么我可以做的事情来继续调用堆栈?
当您使用Control.Invoke()而不是Control.BeginInvoke()时,UI线程上引发的任何异常都会被封送回您的工作线程并重新抛出.有一些信息丢失,你得到最内部的例外.
使用Invoke()很少是正确的,并且通常有可能导致死锁,混淆异常和延迟工作线程.在UI线程执行委托目标之前,哪个被阻止.这可能需要一段时间.确保你确实需要它.如果您调用需要其返回值的方法,那么这才是真正必要的.应始终避免这种情况.
您可以使用Debug + Exceptions调试这些异常,勾选CLR Exceptions的Thrown复选框.调试器现在将停止在抛出异常的代码处.
| 归档时间: |
|
| 查看次数: |
91 次 |
| 最近记录: |