473,382 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

call a function every 5 seconds

Hi,

I want to call a function every 5 seconds, is it possible?
How to?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #1
11 9367
Well, you can have a timer set to tick every 5 seconds, and handle the
event that gets fired? There are two such timers depending on whether it
is for winform or server usage.

Alternatively, you could have a worker thread looping with a Sleep(5000)?

Marc
Jun 27 '08 #2
Is a web page, do you have a example of the code on how to set the tick
for every 5 seconds?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #3
At client side? Well there are javascript ways of doing this in the
browser - setInterval / setTimeout:

http://www.google.com/search?q=setInterval+asp.net

Marc
Jun 27 '08 #4
Sorry - I should have added; for more information, you might want to try
asking on one of the ASP.NET forums, but a clientside javascript call is
a bit OT for a C# language forum.

Marc
Jun 27 '08 #5
I want to be on server side...

I don't want to write javascript

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #6
Well, short of a meta-refresh, you can't.

A html page lives at the client. The server can't do anything once the
page has gone to the client - the client has to deal with that.

Marc
Jun 27 '08 #7
On Thu, 22 May 2008 05:29:05 -0700, Marc Gravell <ma**********@gmail.com>
wrote:
Well, you can have a timer set to tick every 5 seconds, and handle the
event that gets fired? There are two such timers depending on whether it
is for winform or server usage.
Nitpick: not that this helps the OP, but there are at least three timer
classes in .NET. They are in System.Timers, System.Threading, and
System.Windows.Forms.

Pete
Jun 27 '08 #8
On May 22, 12:54*pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Thu, 22 May 2008 05:29:05 -0700, Marc Gravell <marc.grav...@gmail.com*
wrote:
Well, you can have a timer set to tick every 5 seconds, and handle the *
event that gets fired? There are two such timers depending on whether it*
is for winform or server usage.

Nitpick: not that this helps the OP, but there are at least three timer *
classes in .NET. *They are in System.Timers, System.Threading, and *
System.Windows.Forms.

Pete
I need to create a program for a car racer

Jun 27 '08 #9
On Thu, 22 May 2008 05:21:30 -0700, Claudia Fong wrote:
Hi,

I want to call a function every 5 seconds, is it possible? How to?

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***

Trying using Thread.Sleep to "pause" the current thread.

using System.Threading;
public class Test
{
public Test()
{
Thread everyFiveSeconds = new Thread
(FunctionToRunEveryFiveSeconds);
updater.Name = "Updater - Thread";
updater.Start();

}

public FunctionToRunEveryFiveSeconds()
{
object.Do();
Thread.Sleep(5000);
}

public SomeOtherWork()
{
while(true)
{
object.DoSomethingElse();
}
}
}
Regards j1mb0jay
Jun 27 '08 #10
On May 22, 3:22 pm, Claudia Fong <cdolphi...@yahoo.co.ukwrote:
I want to be on server side...

I don't want to write javascript

Cheers!

Claudi

*** Sent via Developersdexhttp://www.developersdex.com***
I think that you can use ajax. But this is based on javascript.
Jun 27 '08 #11
Claudia Fong wrote:
I want to be on server side...

I don't want to write javascript
Doing something server side every N second does not
fit well with the ASP.NET model.

Options I can see:

1) Start a thread (like in global.asax Application_Start) that
updates some global data (like stored in a singleton) every N
second and pages gets info from that global data.

2) Run a Windows service that has the thread that updates some
data every N seconds and have pages request info via
a low overhead protocol (remoting, plain sockets etc.).

#1 is not good (in general it is not good to mess around
with threads in a context where the container manage threads
and there will be extra work to get it to work well over web app
restarts) and #2 is rather complex, but I think
that is the options.

Arne
Jun 27 '08 #12

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

Similar topics

5
by: Vedran Furac | last post by:
How can I call a function every time a specified number of milliseconds elapses? Javascript has setInterval() function and I need something like that. Currently I use this: def function(): t =...
5
by: Lucy Randles | last post by:
I've written a VBA function that I then need to call in a form. Previously to do this I have written the call procedure in the same module as the function - i.e. Function callfunctionname() Call...
4
by: Dave | last post by:
I have a program that I've written a class for. I need to call the function in the program from the class. When I try to call the function I receive the error, the name xxx does not exist in the...
2
by: moondaddy | last post by:
I'm using vb.net and have an aspx page where I want to call a function in the code behind to do something on the backend and I want to call this function from a jscript function in the aspx page. ...
12
by: leaf | last post by:
Hi, How to call function at runtime, based on a struct that contains the information for the function call: struct func_to_call { int function_id; // function id to call unsigned int nparams;...
3
by: James | last post by:
Hi, I have built a windows app that makes calls to a webservice. Both webservice and windows apps are built with .net 2.0. The problem is... when I run the client Windows app on the dev machine,...
4
by: Frank Lund | last post by:
Should we call .Dispose() every chance we get... on every object that exposes .Dispose()... and every time we have such an object? For example, is it true that *every* time I create a DataTable...
3
by: inetquestion | last post by:
How do you enable javascript to execute a given function every X seconds, which is not dependant on any user input? -Inet
1
by: Jian Liang | last post by:
Hi, I have a PHP page named INPUT.php to let respondent answer questions. I have a function named SAVE() save their input into database. I need to call SAVE() every 5 mins automatically . How can...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.