Solved

Windows App Design Question

Posted on 2002-06-12
8
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

724 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