Solved

Windows App Design Question

Posted on 2002-06-12
8
222 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

740 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