473,659 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need some tips on how to implement a timer

Hey guys,

Here is what I am trying to achieve:

I have a grid, and every once in a while the grid will receive a message to
add a new row and highlight it (change the backcolor) for five minutes.
After the five minutes has passed, unhighlight it. The grid needs to
highlight any rows that have arrived in the last five minutes.

Here is how I handle this now. Each row has a value indicating its arrival
time and I have a timer that ticks every 10 seconds. On the timer tick
event, I go through every row in the grid and check if it is highlighted. If
it is, I compare its arrival time to the current time and if the difference
is >= five minutes, I unhighlight it.

I would like the highlighting and unhighlighting to occur as accurately as
possible but ticking every second instead of 10 (or any other higher value)
would loop through all of the rows in the grid every second and that would be
slow since the number of rows may be high.

Does anyone have any other possible suggestions as to how to handle this
scenario?
It would be great if each row can monitor itself and then unhighlight itself
after five minutes but I'm not sure if that is possible.

Thanks for the help,
-Flack
Mar 24 '06 #1
5 2113
vj
You can try this method... have like member variables ( in the class that
carries your grid) that indicate last update time, rowIDs
updated/highlighted. So in row update event you can highlight the current
row that came in and just loop through the previously highlighted rows and
remove them if your condition matches...

HTH
VJ

"Flack" <Fl***@discussi ons.microsoft.c om> wrote in message
news:8B******** *************** ***********@mic rosoft.com...
Hey guys,

Here is what I am trying to achieve:

I have a grid, and every once in a while the grid will receive a message
to
add a new row and highlight it (change the backcolor) for five minutes.
After the five minutes has passed, unhighlight it. The grid needs to
highlight any rows that have arrived in the last five minutes.

Here is how I handle this now. Each row has a value indicating its
arrival
time and I have a timer that ticks every 10 seconds. On the timer tick
event, I go through every row in the grid and check if it is highlighted.
If
it is, I compare its arrival time to the current time and if the
difference
is >= five minutes, I unhighlight it.

I would like the highlighting and unhighlighting to occur as accurately as
possible but ticking every second instead of 10 (or any other higher
value)
would loop through all of the rows in the grid every second and that would
be
slow since the number of rows may be high.

Does anyone have any other possible suggestions as to how to handle this
scenario?
It would be great if each row can monitor itself and then unhighlight
itself
after five minutes but I'm not sure if that is possible.

Thanks for the help,
-Flack

Mar 24 '06 #2
Hi Flack,

A lot depends on what you mean by "grid." There is no class by that name.
Does anyone have any other possible suggestions as to how to handle this
scenario?
It would be great if each row can monitor itself and then unhighlight
itself
after five minutes but I'm not sure if that is possible.
I think you're basically on the right track there. You have a few
alternatives. One would be to inherit whatever class the "grid" row is, and
add a timer to that class which is started when the row is created, and
fires its elapsed event after a configurable interval (5 minutes by default,
but you always want to be able to change it).

When the timer fires its event, it is stopped and disposed, so that it only
fires once, when it is needed. Again, depending upon the "grid" you're
working with, the inherited row class could either unhighlight itself, or
raise an event that signals the "grid" to unhighlight it.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Flack" <Fl***@discussi ons.microsoft.c om> wrote in message
news:8B******** *************** ***********@mic rosoft.com... Hey guys,

Here is what I am trying to achieve:

I have a grid, and every once in a while the grid will receive a message
to
add a new row and highlight it (change the backcolor) for five minutes.
After the five minutes has passed, unhighlight it. The grid needs to
highlight any rows that have arrived in the last five minutes.

Here is how I handle this now. Each row has a value indicating its
arrival
time and I have a timer that ticks every 10 seconds. On the timer tick
event, I go through every row in the grid and check if it is highlighted.
If
it is, I compare its arrival time to the current time and if the
difference
is >= five minutes, I unhighlight it.

I would like the highlighting and unhighlighting to occur as accurately as
possible but ticking every second instead of 10 (or any other higher
value)
would loop through all of the rows in the grid every second and that would
be
slow since the number of rows may be high.

Does anyone have any other possible suggestions as to how to handle this
scenario?
It would be great if each row can monitor itself and then unhighlight
itself
after five minutes but I'm not sure if that is possible.

Thanks for the help,
-Flack

Mar 24 '06 #3
Thanks for the reply vj.

Your method would work fine if I only needed to change the highlighting when
a row is added. However I can't use the row update event because I may have
received, let's say, 10 rows at once, and then no more rows for a long time.
I still need to be able to unhighlight those 10 rows after five minutes have
passed since they arrived.

I'm starting to think that using a timer to check the rows at certain
intervals is the only way.

"vj" wrote:
You can try this method... have like member variables ( in the class that
carries your grid) that indicate last update time, rowIDs
updated/highlighted. So in row update event you can highlight the current
row that came in and just loop through the previously highlighted rows and
remove them if your condition matches...

HTH
VJ

"Flack" <Fl***@discussi ons.microsoft.c om> wrote in message
news:8B******** *************** ***********@mic rosoft.com...
Hey guys,

Here is what I am trying to achieve:

I have a grid, and every once in a while the grid will receive a message
to
add a new row and highlight it (change the backcolor) for five minutes.
After the five minutes has passed, unhighlight it. The grid needs to
highlight any rows that have arrived in the last five minutes.

Here is how I handle this now. Each row has a value indicating its
arrival
time and I have a timer that ticks every 10 seconds. On the timer tick
event, I go through every row in the grid and check if it is highlighted.
If
it is, I compare its arrival time to the current time and if the
difference
is >= five minutes, I unhighlight it.

I would like the highlighting and unhighlighting to occur as accurately as
possible but ticking every second instead of 10 (or any other higher
value)
would loop through all of the rows in the grid every second and that would
be
slow since the number of rows may be high.

Does anyone have any other possible suggestions as to how to handle this
scenario?
It would be great if each row can monitor itself and then unhighlight
itself
after five minutes but I'm not sure if that is possible.

Thanks for the help,
-Flack


Mar 26 '06 #4
Sorry about that.

The "grid" I am using is a FlexGrid for .NET control, from ComponentOne.
It's like .NETs standard DataGrid but with more features.

I have a data table that is bound to the grid and the data table is where
the rows come in. I'm assuming that any method used to solve this problem
would work the same regardless of whether I am using a C1 FlexGrid or a
regular .NET DataGrid.

"Kevin Spencer" wrote:
Hi Flack,

A lot depends on what you mean by "grid." There is no class by that name.
Does anyone have any other possible suggestions as to how to handle this
scenario?
It would be great if each row can monitor itself and then unhighlight
itself
after five minutes but I'm not sure if that is possible.


I think you're basically on the right track there. You have a few
alternatives. One would be to inherit whatever class the "grid" row is, and
add a timer to that class which is started when the row is created, and
fires its elapsed event after a configurable interval (5 minutes by default,
but you always want to be able to change it).

When the timer fires its event, it is stopped and disposed, so that it only
fires once, when it is needed. Again, depending upon the "grid" you're
working with, the inherited row class could either unhighlight itself, or
raise an event that signals the "grid" to unhighlight it.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Flack" <Fl***@discussi ons.microsoft.c om> wrote in message
news:8B******** *************** ***********@mic rosoft.com...
Hey guys,

Here is what I am trying to achieve:

I have a grid, and every once in a while the grid will receive a message
to
add a new row and highlight it (change the backcolor) for five minutes.
After the five minutes has passed, unhighlight it. The grid needs to
highlight any rows that have arrived in the last five minutes.

Here is how I handle this now. Each row has a value indicating its
arrival
time and I have a timer that ticks every 10 seconds. On the timer tick
event, I go through every row in the grid and check if it is highlighted.
If
it is, I compare its arrival time to the current time and if the
difference
is >= five minutes, I unhighlight it.

I would like the highlighting and unhighlighting to occur as accurately as
possible but ticking every second instead of 10 (or any other higher
value)
would loop through all of the rows in the grid every second and that would
be
slow since the number of rows may be high.

Does anyone have any other possible suggestions as to how to handle this
scenario?
It would be great if each row can monitor itself and then unhighlight
itself
after five minutes but I'm not sure if that is possible.

Thanks for the help,
-Flack


Mar 26 '06 #5
The System.Threadin g.Timer class is well suited for this task. For each row
added, create a new timer can set it to fire once in 5 minutes like:
Timer t = new Timer(callback, yourRowObject, TimeSpan.FromMi nutes(5),
Timeout.Infinit e);

Add the timer object to a row Tag or something. When it fires, your row
object will be passed to your callback and you can unhightlight the row and
dispose() the timer object. That way you don't poll or spin and your rows
will unhightlight as close to exactly five minutes as you can get.
Internally, this uses a timer queue so only the "nearest" timer is waiting,
so this can scale to 100's of thousands of timers and works well.

--
William Stacey [MVP]

"Flack" <Fl***@discussi ons.microsoft.c om> wrote in message
news:8B******** *************** ***********@mic rosoft.com...
| Hey guys,
|
| Here is what I am trying to achieve:
|
| I have a grid, and every once in a while the grid will receive a message
to
| add a new row and highlight it (change the backcolor) for five minutes.
| After the five minutes has passed, unhighlight it. The grid needs to
| highlight any rows that have arrived in the last five minutes.
|
| Here is how I handle this now. Each row has a value indicating its
arrival
| time and I have a timer that ticks every 10 seconds. On the timer tick
| event, I go through every row in the grid and check if it is highlighted.
If
| it is, I compare its arrival time to the current time and if the
difference
| is >= five minutes, I unhighlight it.
|
| I would like the highlighting and unhighlighting to occur as accurately as
| possible but ticking every second instead of 10 (or any other higher
value)
| would loop through all of the rows in the grid every second and that would
be
| slow since the number of rows may be high.
|
| Does anyone have any other possible suggestions as to how to handle this
| scenario?
| It would be great if each row can monitor itself and then unhighlight
itself
| after five minutes but I'm not sure if that is possible.
|
| Thanks for the help,
| -Flack
Mar 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1313
by: Aaron Leung | last post by:
Hi everyone, I want to take a shot at implementing a simple framework for functional reactive programming in Python. (It will be loosely based on a paper I read about a system called FrTime for DrScheme.) However, I'm not sure how to go about implementing certain components. One basic component will be an object representing the current time (preferably down to, say, 10 ms). This time object should update itself autonomously. ...
1
574
by: wukexin | last post by:
I write my own class Cfile, I want to know what about implement ctime().Who help me? My use function ctime, I sign it with $$$. my class Cfile: #------------------------ file.h #--------------------------- #include <io.h> #include <ctime> #include <string>
4
1305
by: Jeff | last post by:
IDE: VS .NET 2003 OS: XP pro sp2 I'm developing a server application, clients will connect to it over the net and start different tasks.... When people sends a command to the program, the command is first placed into ThreadPool for await processing... Here is the what I'm having problem with:
7
2395
by: Cheryl Langdon | last post by:
Does anyone know if there is a way to globally turn off ALL control tips in Access 2003 using VBA code? Thanks. --- CL
4
1906
by: Lemune | last post by:
Hello everyone. I'm using vb 2005. I'm creating program that run as service on windows. And in my program I need to use timer, so I'm using timer object from component. I try my source code on another project that use windows form and it work. But when I implement my source code on my program that run as service on windows (I have change the code so it would work on service but I still use timer object from component), and it doesn't...
4
2136
by: rockkyy | last post by:
hi, i am storing a random token and userid,clientdata etc on a STL map container with the unique token as the KEY and the structure containg userid,clientdata etc as the VALUE. Now i want to delete a token-Structure pair every 2 days. How will i know a particular token has expired? Can i add another value on to the structure containing a time stamp of when it was created? Then after every 2 days some timer will expire which will trigger...
2
2564
by: Thomas Ploch | last post by:
Hello folks, I am having troubles with implementing a timed queue. I am using the 'Queue' module to manage several queues. But I want a timed access, i.e. only 2 fetches per second max. I am horribly stuck on even how I actually could write it. Has somebody done that before? And when yes, how is the best way to implement it? Thanks, Thomas
19
40807
by: UG | last post by:
I just wanted to know whether any timer facility exists in C, as it is not mentioned in K&R 2, or in the ISO Draft. By timer function i mean that when we use standard input function like scanf() or getch() or any other function, the interface stops to take input from user but what if user doesn't give input for hours, the program will still be waiting. Is there any way to circumvent the scanf() (or any other input function for that matter)...
14
1505
by: Rex | last post by:
Re: Looking for Tips/Writeup on overall approach to Exception Processing Hi All - I am fairly new to C# and am wondering how to best implement (overall) Exception Processing within my (reasonably-sized) C# Windows application. I do have a bunch of somewhat random questions on this and if you can help me with only one or a few, that would still be APPRECIATED. Here are my questions: 1. Is it recommended to put all of the "Main" coding...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8339
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8535
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.