Tuesday, November 8, 2011

So that your threads do not tangle..


I had never thought an application could crash of an unsafely handled label. But this did happen with me once when this exception popped up out of nowhere and said: InvalidOperationException : Control label1 accessed from a thread other than the thread it was created on. As .Net developers, we usually assume that all such stuff is being taken care of by the framework or the visual studio. Hence this was something new for me. As I figured out, this is a compile time exception which occurs to warn the developer of a situation when more than one thread would try to access the same control and hence get locked. This exception usually occurs during compile time and reliably during debugging and sometimes during run-time.