Solved

Windows App Design Question

Posted on 2002-06-12
8
216 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 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