473,809 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
+ 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 6187
Mike P <mr*@telcoelect ronics.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.co m>
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************* *@exisconsultin g.com

"Mike P" <mr*@telcoelect ronics.co.uk> wrote in message
news:uV******** ******@tk2msftn gp13.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.C lose

Set rsTransaction = CreateObject("A DODB.Recordset" )

rsTransaction.O pen strTransaction & Session("Sessio nID") & "AND ID =
" & Session("ID"), connSession, adOpenStatic, _
adLockReadOnly, adCmdText
If Not rsTransaction.E OF Then strNewStatus =
rsTransaction.F ields("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
3645
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 identity. In order to correct this problem I've modified the Machine.config file in the \Microsoft.Net\Framework\v1.1.4322 folder. However, this didn't solve the problem; instead of using the user id and password specified in Machine.Config, the...
5
2143
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 user requests the page, the app first tries to retrieve a feed from cache, if the feed has expired, it goes off and request the file from the web. If create a CacheItemRemovedCallback for each item to automatically re-request an expired...
6
2915
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. When I make calls to SetWindowLong and SetLayeredWindowAttributes using the window handle for a poup form in Access, and call from within a timer event handler, it works most of the time, but sometimes will stop the timer from firing until I click...
1
3305
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 objects which all fire into my OnTimer( object state ) function very nicely. I pass in an object "o" on creation of this timer which I subsequently get passed to me in my OnTimer function. Now in the OnTimer function I want to modify the object...
10
1665
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 seconds. I set up a singleton class that's instantiated when the app starts, and that starts a timer. My question is, would it be better to run this checking process on a separate thread and have it use its own DB connection? If there isn't a...
7
6097
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 seems recently connections just drop off because the timer stops firing. My question is if there is a timeout in the timer event that just shuts down the call if the timer event is taking too long to complete...?
12
5539
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 directories and updating a database. No interaction with the GUI. Problem is that the system timers do not have a tag property so I can tie in an object. example (old way):
11
2612
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 library as I thought this would be a good start!!!) but nothing happens :- Imports System.Timers
16
3260
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 do it. If I bring this same code outside this event handler, it works just fine. Is this normal?
11
4245
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 Timer (in VB 2005) this is exactly the syntax shown. I also tried:
0
9721
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
10120
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...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7661
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
6881
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
5550
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...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
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
3
3015
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.