Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Windows App Design Question

Posted on 2002-06-12
8
Medium Priority
?
231 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 200 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 October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free 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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 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