考虑以下内容:
class Client
{
public static event EventHandler connectFailed;
private Socket socket;
public Client()
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endpoint = new IPEndpoint(
IPAddress.Parse("192.168.1.100"),
7900
);
try
{
socket.Connect(endpoint);
}
catch(Exception e)
{
connectFailed(e, new EventArgs());
}
}
}
假设剩下的代码已经实现(在Program.cs中的事件处理程序等)。
我遇到了一个问题,connectFailed(e, new EventArgs());
这一行出现了NullRefrerenceException
异常,而我无法理解原因。我的其他事件都能正常触发,我不明白这个与其他事件有什么不同。
有什么想法吗?