Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 18th, 2006, 05:59 AM
Authorized User
Join Date: Mar 2004
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Timer Or Thread? (c#)

hi, please help me.
I want to run timer (or thread) that checks every 5 sec something in my code and then doing corresponding action.
At the same time the methods must be invoked normally.
It means that it is a kind of interrupt every 5 sec while running the program.


Reply With Quote
  #2 (permalink)  
Old July 18th, 2006, 08:45 AM
Registered User
Join Date: Sep 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to silver_scar

Hi Koby,

Am new at this. but since you used the word "interrupt", I am assuming that you dont want to be blocked. This is what suggest. I think thread should do the job for you.

You have your main thread and you create another Checker thread.

The checker thread does whatever you want to check for and then sleeps for 5 seconds. I am assuming that sleep() in C# is non-blocking.

Alternate idea ...

use a timer, which when expires will pass the control to something like OnTimerExpired() which will do your checking ... but since I havent done much with timers I am not sure if it will be as it sounds

Reply With Quote
  #3 (permalink)  
Old July 21st, 2006, 10:44 AM
Authorized User
Join Date: Jul 2004
Location: , , .
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post

This is a typical solution for a Timer and not a constant thread (though both are technically possible). if you are using a windows form then you can simply drag a timer on the form and implement the Timer.Tick event. There are other types of timer in the framework as well. The benefits of using the System.Windows.Forms.Timer in a Windows Form is that the form will get priority for refreshing, instead of the Timer event.

This gives a good explaination of the Forms Timer... http://www.c-sharpcorner.com/controls/timer.asp

Get A Computer Job!

Computer Parts & Accessories
Reply With Quote
  #4 (permalink)  
Old July 22nd, 2006, 12:21 AM
Friend of Wrox
Join Date: May 2006
Location: Delhi, Delhi, India.
Posts: 106
Thanks: 0
Thanked 0 Times in 0 Posts

Thread t1=new Thread(f1); //
// in the constructor or form load event

private void f1()
// Call the requred function;
Thread.Sleep(1000/12); // or pass any value of time in microsec.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which Thread to use and How peace2007 ASP.NET 1.0 and 1.1 Professional 0 September 23rd, 2007 03:24 AM
Countdown Timer stalkingbutler Access VBA 2 April 16th, 2007 10:44 AM
Timer Dhanapal ADO.NET 2 April 16th, 2007 04:58 AM
Timer prasanta2expert Access VBA 1 November 8th, 2006 09:28 AM
timer amerei ASP.NET 1.0 and 1.1 Professional 0 October 15th, 2005 10:49 PM

All times are GMT -4. The time now is 04:08 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.