所以我有这段代码负责远程计算机的命令确认,有时(比如 14 天一次或其他什么)以下行会引发空引用异常:
computer.ProcessCommandAcknowledgment( commandType );
真正让我烦恼的是我在它之前检查了一个空引用,所以我不知道发生了什么。这是其价值的完整方法:
public static void __CommandAck( PacketReader reader, SocketContext context )
{
string commandAck = reader.ReadString();
Type commandType = Type.GetType( commandAck );
Computer computer = context.Client as Computer;
if (computer == null)
{
Console.WriteLine("Client already disposed. Couldn't complete operation");
}
else
{
computer.ProcessCommandAcknowledgment( commandType );
}
}
有什么线索吗?
编辑:ProcessCommandAcknowledgement:
public void ProcessCommandAcknowledgment( Type ackType )
{
if( m_CurrentCommand.GetType() == ackType )
{
m_CurrentCommand.Finish();
}
}