N
news
..Net 2.0
Hi, I'm getting a nullreferenceexception when calling a function from a
worker thread:
private void CallbackProc(string response, Exception ex)
{
if (this.InvokeRequired)
{
this.Invoke(new MyCallback(CallbackProc), new object[] {
response, ex });
}
else
{
// do stuff here on the ui thread
}
}
It is true that ex is indeed null in some calls of CallbackProc, but
not always. The exception is thrown whenever ex is indeed null.
However, the documentation doesn't say that I can't pass null in an
Invoke (indeed it seems to say the opposite). So, I tried it out with a
fresh project but this time from one thread. (I.e. no worker thread.)
Ok, it was a hack because I replaced the "this.Invokerequired" with a
flag to ensure it only looped once. Anyway, the point is that it
worked: Invoke was happy to have a null argument in the object array.
My final test was to enclose the Invoke in a try catch. Surprisingly,
although the exception is still thrown, the Invoke call is still made
and works exactly as I want it to! Weird!
I could leave it with the try catch but that's horrible. So, can
someone point me in the right direction please?
TIA
Hi, I'm getting a nullreferenceexception when calling a function from a
worker thread:
private void CallbackProc(string response, Exception ex)
{
if (this.InvokeRequired)
{
this.Invoke(new MyCallback(CallbackProc), new object[] {
response, ex });
}
else
{
// do stuff here on the ui thread
}
}
It is true that ex is indeed null in some calls of CallbackProc, but
not always. The exception is thrown whenever ex is indeed null.
However, the documentation doesn't say that I can't pass null in an
Invoke (indeed it seems to say the opposite). So, I tried it out with a
fresh project but this time from one thread. (I.e. no worker thread.)
Ok, it was a hack because I replaced the "this.Invokerequired" with a
flag to ensure it only looped once. Anyway, the point is that it
worked: Invoke was happy to have a null argument in the object array.
My final test was to enclose the Invoke in a try catch. Surprisingly,
although the exception is still thrown, the Invoke call is still made
and works exactly as I want it to! Weird!
I could leave it with the try catch but that's horrible. So, can
someone point me in the right direction please?
TIA
For anyone else following this, here's the bug. Thanks to