473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ActiveFrom in a windows application

Hi , i am developing a winforms application.
I have four forms which is inherited from Baseform in another project .
In all four forms i am using a label to show some transaction count based on network status. 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.
Please help me , how to get an active forms of an application.


Expand|Select|Wrap|Line Numbers
  1. Private Sub StartThread() 
  2. pollThread =New Thread(AddressOf PollfileStatus) 
  3. pollThread.IsBackground =True
  4. running =True
  5. pollThread.Start()
  6. End Sub
  7.  
  8. Private Sub PollfileStatus() 
  9. While (running)
  10. Try
  11. For Each e As Control In Me.ActiveForm.Controls 
  12. If (e.Name = "pbStatus") Then
  13. e.Invoke(New SetTextCallback(AddressOf Settext), New Object() {e, 10}) 
  14. End If
  15. Next
  16. Catch ex As Exception 
  17. Throw New ApplicationException(ex.Message) 
  18. End Try
  19. Thread.Sleep(6000)
  20. End While
  21. End Sub
Oct 7 '09 #1
2 1335
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Oct 7 '09 #2
tlhintoq
3,525 Expert 2GB
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.

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?
Oct 7 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael | last post by:
Hi, I have a windows service developed using c# and it needs to lunch another windows application. I have been trying to use Process class to do it but the problem is becase windows service...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
9
by: SP | last post by:
Hi All, I wrote a windows service which is supposed to stop after specified amount of time. I am calling OnStop() after specified time. OnStop() methods executed but I dont see the service...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
15
by: =?Utf-8?B?TVNU?= | last post by:
To demonstrate my problem, I have a very simple VB Windows application. It has a text box that is used to display a counter, a button to reset the counter, and a timer that increments the counter...
2
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
1
by: =?Utf-8?B?dmlzaHJ1dGg=?= | last post by:
Hi, I have 2 applications running, one Windows application project and the other windows services project. I want to call my Windows application in my windows services. I want to run them as...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: List of autostart locations Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list all the autostart locations for windows? Ans: Here is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.