Need an inner loop to keep going while an outer loop loops

dlvonde

Active member
Joined
Oct 26, 2007
Messages
26
Programming Experience
1-3
OK I don't know how to describe the problem in one sentence.

I have an application I've been working on that monitors hardware stats on multiple pc's..things like hard drive free space, memory usage, cpu utitilization, etc.

I am using custom user controls to show all these stats so that each computer's information is represented in a tabControl. I created a loop that loops through each computername in an array and grabs the info about that computer then adds it to a flowlayoutpanel.

The Problem:
each new userControl that is created represents a different server, and I need for the information inside that userControl to be polled for the server it represents every few seconds.

So if I make my usercontrol run on a loop to poll for information every few seconds then it never breaks out of itself so my "outer loop" can create the next userControl.

so I'm guessing I'm needing to know if I can create a new userControl, let it start doing it's thing, but allow the computer to keep on creating more userControls?

thanks
 
fantastic!

thanks for your help and helping me to get my head around what's really happening.

I made another class just as you said and declared all the variables pretty much the same as they are in my usercontrol class so as not to have any confusion. it's working wonderfully.

the only issue now is when i close the form it gives an error presumably because it's not closing down the background worker. I tried to set the form.closing event to shut down the background worker but realized that it is in the usercontrol class and not the form class.
 
The BackgroundWorker uses a thread pool thread, so it is genuinely a background thread. When you create a Thread explicitly it is still a foreground thread by default, unless you set its IsBackground property to True. If you test the Thread.CurrentThread.IsBackground property inside the DoWork event handler of a BackgroundWorker you'll se that it is True.

The differences are two:

1. Background threads have a slightly lower priority than foreground threads.

2. While a foreground thread is running your process will not exit. Background threads will be implicitly ended if you try to exit your process.

That means that if you exit the process the worker thread(s) will be ended implicitly. That may be a problem if doing so leaves your data in an invalid state. Also, if you're not exiting the process but not closing the form then it may be that, while your BackgroundWorker(s) is getting disposed the actual thread it started is still executing. In that case you should provide some way to test whether the worker is still working and defer closing until it finishes.
 
I'll try that out tonight during another coding marathon :).

Once I have it all working how I want to is it possible to embed the VB object (either the form or the customUserControl in a webpage?

This is just a "would be nice" feature but I wanted to know if it was simple to do?

It would be nice to be able to just pull up a webpage and have the controls populate in the page...
 
Windows Forms controls and Web controls are different things. If you want to put your control on a Windows Form then you derive from System.Windows.Forms.UserControl. If you want to put it on a Web page then you inherit System.Web.UI.UserControl. Any types that are not specific to either Web or Windows development can be used in either, but remember that in Web apps you must differentiate between code that gets executed server-side and code that gets executed client-side.
 
Back
Top