473,466 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

timer question

I have a loop which goes thorough a recordset until a particular value
in the recordset changes. In situations where the value doesn't change,
I would like to use a timer to check whether 60 seconds have elapsed, in
which case I exit the loop.

I'm not really sure how to do this as I'm new to C#. I've tried to use
the Timer.Elapsed, but I'm not sure how I can use this condition to exit
my loop.
Any help would be much appreciated.
Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #1
3 6175
Mike P <mr*@telcoelectronics.co.uk> wrote:
I have a loop which goes thorough a recordset until a particular value
in the recordset changes. In situations where the value doesn't change,
I would like to use a timer to check whether 60 seconds have elapsed, in
which case I exit the loop.

I'm not really sure how to do this as I'm new to C#. I've tried to use
the Timer.Elapsed, but I'm not sure how I can use this condition to exit
my loop. Any help would be much appreciated.


The easiest way would be to use DateTime.Now:

DateTime start = DateTime.Now;
TimeSpan timeout = new TimeSpan (0, 1, 0); // One minute

while (...)
{
if (DateTime.Now-start > timeout)
break;

// do whatever

Thread.Sleep (1000); // Don't just tight-loop!
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 13 '05 #2
Mike,

I am curious, why are you wasting resources when you can just hook into
the event structure of the DataSet or DataTable.

You said "recordset", so the possibility exists that you are using an
ADO Recordset. If so, there are events that the ADO Recordset throws to
indicate that a change is taking place.

Either of these solutions would be better than wasting a thread polling
for changes and then sleeping in between polls.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mike P" <mr*@telcoelectronics.co.uk> wrote in message
news:uV**************@tk2msftngp13.phx.gbl...
I have a loop which goes thorough a recordset until a particular value
in the recordset changes. In situations where the value doesn't change,
I would like to use a timer to check whether 60 seconds have elapsed, in
which case I exit the loop.

I'm not really sure how to do this as I'm new to C#. I've tried to use
the Timer.Elapsed, but I'm not sure how I can use this condition to exit
my loop.
Any help would be much appreciated.
Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #3
Thanks for your replies. Basically I am converting an ASP website
written in VB Script to ASP.NET with C#. Being my first project in
either ASP.NET or C#, I'm not very good with the terminology yet...when
I said recordset I meant the .NET equivalent!

The code that I was looking at that I thought might be a problem
converting was this :

Do While strNewStatus = "0" Or _
strNewStatus = "1"

rsTransaction.Close

Set rsTransaction = CreateObject("ADODB.Recordset")

rsTransaction.Open strTransaction & Session("SessionID") & "AND ID =
" & Session("ID"), connSession, adOpenStatic, _
adLockReadOnly, adCmdText
If Not rsTransaction.EOF Then strNewStatus =
rsTransaction.Fields("Status").Value
If timer() - StartTime >= 60 Then Exit Do
Loop

A VB6 application is running in the background which may or may not
change the strNewStatus value from it's default of 0 in the database on
the same machine. Therefore, I need some way of exiting the loop in
case this value does not change.

I have so far done a bit of work using data readers, and I don't forsee
having any problems with the data access side of things, although I
thought that I would have a problem with the timer side. Jon's reply
definitely worth looking into, though if you know of a better way to go
about this, then let me know.

Thanks for your time,

Mike
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #4

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

Similar topics

3
by: brian | last post by:
I have an ASP.Net application that uses impersonation. This works fine for accessing/executing the application. However, the app utilizes a timer, that when fired uses the <machine>ASPNET...
5
by: Richard P | last post by:
I need some help on timers. My app is asp.net 1.1 website running in a shared hosting environment with a third-party service provider. I currently request and cache 20 - 40 remote RSS feeds. When a...
6
by: Steve Jorgensen | last post by:
I know quite well that this question falls into the category of "why does Access misbehave when I do unexpected things to its objects?", but I thought I'd ask anyway, and see if anyone knows. ...
1
by: Paul Tomlinson | last post by:
Question about a System.Threading.Timer object and the "state" object you pass to it... Timer stateTimer = new Timer( = new TimerCallback( OnTimer ), o, 1000, 1000); I have an array of timer...
10
by: Bob | last post by:
Okay, I've done this for years but now I'm going to question it just because this idea has been at the back of my head since I started using DotNet... My WinForms app queries a database every 60...
7
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it...
12
by: Gina_Marano | last post by:
I have created an array of timers (1-n). At first I just created windows form timers but I read that system timers are better for background work. The timers will just be monitoring different...
11
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn...
16
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not...
11
by: Anil Gupte/iCinema.com | last post by:
When I use this Dim instance As New Timer I get the error: Error 1 Overload resolution failed because no accessible 'New' accepts this number of arguments. Yet, in the help section for...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.