[2013-03-27 09:50:21] 来自“Service1”的全局异常。Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.详细信息如下:
[InnerException]
[Source]System
[TargetSite]Int32 EndSend(System.IAsyncResult, System.Net.Sockets.SocketError ByRef)
[StackTrace] at System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult, SocketError& errorCode)
at System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult)
at netlib.Server.TcpSvr.SendDataEnd(IAsyncResult iar)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(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.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
[2013-03-27 09:50:21] 来自“Service1”的全局异常。Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.详细信息如下:
[InnerException]
[Source]System
[TargetSite]Int32 EndSend(System.IAsyncResult, System.Net.Sockets.SocketError ByRef)
[StackTrace] at System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult, SocketError& errorCode)
at System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult)
at netlib.Server.TcpSvr.SendDataEnd(IAsyncResult iar)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(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.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)因为崩溃后,报的全都是系统函数,我不知道自己写的代码哪有问题。到底是因为包冲突,还是缓冲区爆了或其他原因,都不知道。可以知道的是,上行和下行数据量不大,不大可能是包冲突或缓冲区的问题。有经验的前辈可是有遇到过?另外《Cannot access a disposed object》这个的字面意思就不用解释了,程序崩溃,前后没有任何异常数据,数据上来后,所用的无非是我自定义的Session表,然后解包,按照相应的命令发包,并没有调用了已关闭的进程或资源呀,求赐教啊!!!!!service通讯
Object name: 'System.Net.Sockets.Socket'.详细信息如下:
[InnerException]
[Source]System
[TargetSite]Int32 EndSend(System.IAsyncResult, System.Net.Sockets.SocketError ByRef)
[StackTrace] at System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult, SocketError& errorCode)
at System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult)
at netlib.Server.TcpSvr.SendDataEnd(IAsyncResult iar)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(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.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
[2013-03-27 09:50:21] 来自“Service1”的全局异常。Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.详细信息如下:
[InnerException]
[Source]System
[TargetSite]Int32 EndSend(System.IAsyncResult, System.Net.Sockets.SocketError ByRef)
[StackTrace] at System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult, SocketError& errorCode)
at System.Net.Sockets.Socket.EndSend(IAsyncResult asyncResult)
at netlib.Server.TcpSvr.SendDataEnd(IAsyncResult iar)
at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
at System.Net.ContextAwareResult.CompleteCallback(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.Net.ContextAwareResult.Complete(IntPtr userToken)
at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)因为崩溃后,报的全都是系统函数,我不知道自己写的代码哪有问题。到底是因为包冲突,还是缓冲区爆了或其他原因,都不知道。可以知道的是,上行和下行数据量不大,不大可能是包冲突或缓冲区的问题。有经验的前辈可是有遇到过?另外《Cannot access a disposed object》这个的字面意思就不用解释了,程序崩溃,前后没有任何异常数据,数据上来后,所用的无非是我自定义的Session表,然后解包,按照相应的命令发包,并没有调用了已关闭的进程或资源呀,求赐教啊!!!!!service通讯
好好想想你自己的发送逻辑,一般情况下都是代码逻辑,执行顺序上出的问题
这时在回调函数中调用socke.EndSend就会出现ObjectDisposed异常。你可以:
方法一、捕获并处理ObjectDisposed异常。
方法二、Dispose socket前设定一个标记,如果该标记设定,就不调用EndSend。lock(obj)
{
socketDisposed = true;
socket.Dispose();
}lock(obj)
{
if(!socketDisposed)
{
socket.EndSend(...);
}
}