Solved

Windows App Design Question

Posted on 2002-06-12
8
204 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:larockd
  • 4
  • 3
8 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 7075237
If you want a different interval for each sperate item you have you will need to create yourself a new class which derives from a ListItem. You can add a property to the listitem which contaisn the interval, and add a timer to the listview which is attached to the interval. Whenever the timer fires you reinitialize the ListItem.


Code would look a bit like:

public class MyListItem : ListItem
{
   private System.Windows.Forms.Timer timer1;
   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(refreshit);
      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
0
 

Expert Comment

by:dhaya
ID: 7075991
learning..
0
 

Author Comment

by:larockd
ID: 7076057
CJ,

Thats a very good idea, I am at work now and will try this out later this evening.

dl
0
 

Author Comment

by:larockd
ID: 7077148
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
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Accepted Solution

by:
CJ_S earned 50 total points
ID: 7077679
I think you are are right. The pinging (I assume you are creating such a program, and I myself have finished such an application two weeks ago, but in VB).

WHat I would do is indeed create timer in the site class. The site class needs to call the webmon functions and thus should contain an object of this type.

Inside the site class you define a timer, add an eventhandler to it and create the properties to set and get the interval. Define these to your likings.

Then to update the listview you would set a reference to the corresponding ListItem (or ListRow) inside your site class. You can put this in the constructor of your site class, or create an additional function in which you set a reference to the ListItem.

I hope this explanation would give you enough information including the above source code which you can probably extend to the functionality you want to achieve.

regards,
CJ
0
 

Author Comment

by:larockd
ID: 7078659
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
 
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 7081603
Sure thing!
0
 

Author Comment

by:larockd
ID: 7083648
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
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now