473,513 Members | 2,420 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 2106
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***@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.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***@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.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.Threading.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.FromMinutes(5),
Timeout.Infinite);

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***@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.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
1307
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...
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...
4
1303
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...
7
2384
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
1892
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...
4
2123
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...
2
2545
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...
19
40771
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...
14
1488
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...
0
7259
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,...
0
7158
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...
0
7380
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,...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
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...
1
5085
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...
0
4745
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...
0
1592
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 ...
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.