larockd
asked on
Windows App Design Question
This is my first bout at writing a windows app. I have a basic app
that when it starts it displays a listview with items that I have
populated. Each item that was displayed in the listview has a time
interval associated with it. So after a set amount of time I need to
run a given function and update the listview.
When the app starts at the main entry point it first initializes and
calls the constructor of the class and I cant place it in the
constructor because at that point the app is not running. When the
constructor finishes it calls the Application.Run(yourForm).
My question is that I am not exactly sure where or how do I accomplish
something like this. I thought of two ideas and was not sure if I was
on the right path.
1.) I could use the timer class and tie in an event handler to it.
2.) I could spawn off multiple threads, one to launch the app and one
to monitor the items.
Thanks For Any Guidance.
dl
that when it starts it displays a listview with items that I have
populated. Each item that was displayed in the listview has a time
interval associated with it. So after a set amount of time I need to
run a given function and update the listview.
When the app starts at the main entry point it first initializes and
calls the constructor of the class and I cant place it in the
constructor because at that point the app is not running. When the
constructor finishes it calls the Application.Run(yourForm).
My question is that I am not exactly sure where or how do I accomplish
something like this. I thought of two ideas and was not sure if I was
on the right path.
1.) I could use the timer class and tie in an event handler to it.
2.) I could spawn off multiple threads, one to launch the app and one
to monitor the items.
Thanks For Any Guidance.
dl
learning..
ASKER
CJ,
Thats a very good idea, I am at work now and will try this out later this evening.
dl
Thats a very good idea, I am at work now and will try this out later this evening.
dl
ASKER
CJ,
I didn't get a chance to try this out this evening, but I was able to give this more thought in regards to my program.
Basically, I have two classes one called site and one called webmon. Now the site class contains information on a site (i.e name, uptime, location, last time checked, current status, etc). The webmon class is the class I use to create the application (derived from form).
When webmon starts in addition to creating the app, it creates the listview, initializes all the sites (there can be an unlimited number of sites) configuration data.
I am having a conceptual problem with setting the timer on each individual listview item. I only use the listview to display the sites status (output).
Some reason I think I should be setting the timer in the site class based on the sites check interval.
Any thoughts?
dl
I didn't get a chance to try this out this evening, but I was able to give this more thought in regards to my program.
Basically, I have two classes one called site and one called webmon. Now the site class contains information on a site (i.e name, uptime, location, last time checked, current status, etc). The webmon class is the class I use to create the application (derived from form).
When webmon starts in addition to creating the app, it creates the listview, initializes all the sites (there can be an unlimited number of sites) configuration data.
I am having a conceptual problem with setting the timer on each individual listview item. I only use the listview to display the sites status (output).
Some reason I think I should be setting the timer in the site class based on the sites check interval.
Any thoughts?
dl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It absolutly does help me out CJ, I am going to work on this some more this evening when I get home from work. As far as I am concerned this question is locked, I am going to leave it open until I work on this somemore tonight, in case I have a question or two if thats ok..
dl
dl
Sure thing!
ASKER
CJ,
Thanks I didnt get as much done as I wanted to until last night and everything worked as you had outlined it would.
Is there some known or good programming practice on the limitations of timers? I guess what I am asking is that is there a limit when you set too many timers?
thanks
dl
Thanks I didnt get as much done as I wanted to until last night and everything worked as you had outlined it would.
Is there some known or good programming practice on the limitations of timers? I guess what I am asking is that is there a limit when you set too many timers?
thanks
dl
Code would look a bit like:
public class MyListItem : ListItem
{
private System.Windows.Forms.Timer
public MyListItem() : base()
{
}
// create a new function which you use to set the value AND the interval. Would look a bit like:
public void Value(string sVal, int iInterval)
{
base.Value = sVal;
timer1 = new System.Windows.Forms.Timer
timer1.Interval = iInterval;
timer1.Tick += new System.EventHandler(refres
timer1.Enabled = true
}
private void refreshit(object sender, System.EventArgs e)
{
MessageBox.SHow("Do anything here to rteinitialize the value")
}
}
So, when you want to add a ListItem you would use
MyListItem i = new MyListItem();
instead of
Listitem i = new ListItem();
Furthermore it will work the same, except for the added functionality!
CJ