I had an old Windows Forms Program which I am trying to convert to WPF but I have an issue where the new program throws a "System.NullReferenceException: Object reference not set to an instance to an object" and I don't know how to resolve it. The "old" code is as following:
if (InvokeRequired) {
try {
Invoke((MethodInvoker)delegate {
PackedReceived((ResponseArgs)Packet);
});
} catch {
return;
}
} else {
PackedReceived((ResponseArgs)Packet);
}
}
The "InvokeRequired" apparently doesn't work in WPF so I changed the code to:
{
if (!Dispatcher.CheckAccess())
{
try
{
Dispatcher.Invoke((MethodInvoker)delegate {
PackedReceived((ResponseArgs)Packet);
});
}
catch
{
return;
}
}
else
{
PackedReceived((ResponseArgs)Packet);
}
}
My new solution doesn't work and throws the exception mentioned above. Does anybody have an idea about this? Thanks in advance.