NullReferenceException

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a multi-threaded VB application and occasionly I get a
'System.NullReferenceException' on a call to
System.Windows.Forms.Control.Refresh. Why is this?

tks
Mark
 
I have a multi-threaded VB application and occasionly I get a
'System.NullReferenceException' on a call to
System.Windows.Forms.Control.Refresh. Why is this?

Are you calling Refresh from a background thread? In general you
should only manipulate UI objects on the thread that created them.


Mattias
 
I'm calling Refresh from the UI thread...though there is some UI manipulation
from a background thread.

Mark.
 
Mattias said:
Are you calling Refresh from a background thread? In general you
should only manipulate UI objects on the thread that created them.

Incidentally, did the rules in this area change in Visual Studio 2005? I'm
sure I read somewhere that they would modify the .NET framework so that
manipulating WinForms UI controls from other threads would no longer cause
any problems, but perhaps I imagined it..?
 
Well, an exception is now thrown immediately informing you that an
attempt to access a control on a thread other than the one that created
it occurred. Updating controls on other threads always has and is
likely to always cause problems. 2.0 is just kind enough to let you
know about the problem up front. Controls are still not thread-safe.

Brian
 
Brian said:
2.0 is just kind enough to
let you know about the problem up front. Controls are still not
thread-safe.

Ah well, that's still an improvement I guess. The thing that always worried
me in v1.1 was that UI updates usually worked, but I was always aware that
at some point they would fail spectacularly and unpredictable. At least it's
predictable this way.

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top