这里的第二个问题......
基本上我遇到了一个在我的程序中抛出的Stackoverflow异常的问题,而且我根本不知道如何找到原因..
我有一个程序,它有一个插件系统,它是一个利用TCP发送和接收数据的程序;服务器 - >客户。我正在制作一个远程控制台插件,当我执行命令'tree'时会出现问题; filesystem entries listing命令。前几秒一切顺利;正在输出命令(从客户端发送到服务器)。接收数据包事件不是线程安全的,所以在API中我提供了一个调用函数(用于调用UI线程上的方法)。因此,在输出时,它将执行以下操作:
Public Sub ClientReadPacket(Sender As IClient, Pipename As String, Values As Object())
Select Case DirectCast(Values(1), ConsoleCommands)
Case ConsoleCommands.Output
ServerGUI.Send(Sub() ConsoleOutput.AppendText(Values(2) & Environment.NewLine))
End Select
End Sub
如您所见,ServerGUI是我为插件开发提供的接口。在实际的程序中 - 在实现GUI接口的类中,我在这里得到一个stackoverflow异常:
Private Sub ISend(del As System.Threading.SendOrPostCallback) Implements IGUI.Send
UIThread.Send(del, Nothing)
End Sub ' The break point is here; I assume that means that the exception ocurs in the line above.
UIThread对象是主线程的同步上下文。
http://i.gyazo.com/870d9667f2272969b650cea836adca50.png
更新:到目前为止,我已将其缩小到以下内容;它经常调用SynchronizationContext.Send()时必然会导致stackoverflow异常,当我在插件中使用Invoke()时会发生同样的情况,它也会产生Stackoverflow异常。
我尝试使用asyncoperation,这不会崩溃,但由于它只是异步是一个问题,因为我的程序在使用Post()时变得没有响应,因为它不断发帖(因为它会发生在asyncoperation发布之前管理下一个数据包。