Suggestion: Don't use Thread.Sleep() if you can at all avoid it and don't have a solid reason for bringing your program to a sudden stop. Everything STOPS when you sleep. No background events on the thread, no paying attention to incoming events, nothing on the thread happens and most times that not really what people want.
Quote:
i have implemented a thread which gets active form of application and settign up the text . Code works fine if application screen is active, if minimize and open any other application , i am getting an null error exception.
That sounds like the correct behavior for what you coded.
In your own words, the thread gets the active form of the application...
When that application has no active form (such as when minimized) it breaks.
If you are getting a null exception then you need to see which object/variable is null. My guess is that it is 'e' around lines 11 and 12. I'm guessing that when "Me.ActiveForms.Controls" returns nothing because there are no active controls, then you try to get the name of that nothing it all breaks. One should not assume the return of any function is going to be something. One should always perform some sort of check to make sure their assumptions are right. if (e != null) for example
You do realize you are throwing the exception, right? In line 17.
Are you catching that elsewhere higher up?