473,226 Members | 1,370 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,226 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 9335
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
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...

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.