Timer Component for VB 2005 .aspx page?

R

Ryan

I'm creating a website that monitors the status of servers using
My.Computer.Network.Ping. I'm looking for a way to fire off my Ping()
function every second or so. I see a Timer control availalble for Windows
forms but it is not listed for my .ASPX page. Is there such a control?

Thanks.
 
S

Steven Cheng[MSFT]

Hello Ryan,

As for the timer component, I assume that you're going to perform some
constant operations in your ASP.NET application. Is this operation
specific to individual webform page or is a application wide
operations(like a backgroun worker...)? The article Cor has provided
demonstrates how to create javascript client-side timer which will
constantly call a script function in the web page's client-sdie html
document. However, if what you want is a server-side backgroun timer, I
think you would need to create a server-side background worker thread or a
System.Timers.Timer instance to do the work .e.g.

==================
void Application_Start(object sender, EventArgs e)
{
Timer timer = new System.Timers.Timer();

HttpContext.Current.Application["g_timer"] = timer;

timer.Elapsed += new ElapsedEventHandler(this.OnTimedEvent);
timer.Interval = 4000;
timer.Enabled = true;


}
===========================

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
R

Ryan

Thanks Steven, this works. However, I have images on my page showing the
status of the servers being pinged and these images are not being changed on
the fly. My Ping function changes the ImageURL property based on whether
the Ping succeeds or fails (green image for success, red for failure). Do I
have to re-load the entire page just to update a single image or is there
another way to get just that image to update dynamically on the page?

Thanks.
 
R

Ryan

Just wanted to add that I know the Ping() function is being called because I
put a msgbox("Ping function called") within the function and it pops up on
the webpage every 2 seconds. All I want to know is how do I change an image
on the page (stored in an Image object). Changing the ImageURL does not
seem to be doing the trick.

Thanks!

Ryan said:
Thanks Steven, this works. However, I have images on my page showing the
status of the servers being pinged and these images are not being changed
on the fly. My Ping function changes the ImageURL property based on
whether the Ping succeeds or fails (green image for success, red for
failure). Do I have to re-load the entire page just to update a single
image or is there another way to get just that image to update dynamically
on the page?

Thanks.


Steven Cheng said:
Hello Ryan,

As for the timer component, I assume that you're going to perform some
constant operations in your ASP.NET application. Is this operation
specific to individual webform page or is a application wide
operations(like a backgroun worker...)? The article Cor has provided
demonstrates how to create javascript client-side timer which will
constantly call a script function in the web page's client-sdie html
document. However, if what you want is a server-side backgroun timer, I
think you would need to create a server-side background worker thread or
a
System.Timers.Timer instance to do the work .e.g.

==================
void Application_Start(object sender, EventArgs e)
{
Timer timer = new System.Timers.Timer();

HttpContext.Current.Application["g_timer"] = timer;

timer.Elapsed += new ElapsedEventHandler(this.OnTimedEvent);
timer.Interval = 4000;
timer.Enabled = true;


}
===========================

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no
rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hello Ryan,

Thanks for your response.

Actually, the background thread or a global Timer approach I mentioned just
provide the capability of executing some background code or tasks. If you
want constantly do some thing and then update a page's UI, I think you'd
better consider Cor's suggestion about use javascript function "setTimeout"
or "setInterval" to execute some script code constantly. And you can use
javascript to update a certain image object's url and that change will take
effect immediately at client-side. e.g.:

var img = document.getElementById("imgTitle");
img.src = "new image url";


If you want to get some certain status info from server-side, you can
consider use xmlhttp components to send request to server page or handler
and get updated info. (AJAX is just such a technology which provide
non-refresh communication between client and server in web application).


#Client Script in ASP.NET Web Pages
http://msdn2.microsoft.com/en-us/library/3hc29e2a.aspx

#setTimeout or setInterval
http://javascript.about.com/library/blstvsi.htm

http://www.evolt.org/article/Using_setInterval_to_Make_a_JavaScript_Listener
/17/36035/

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Hello Ryan,

How are you doing on this issue? Does my further reply helps a little?
Please feel free to post here if there is still anything we can help you.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
R

Ryan

Hi Steven,

Actually this project has gotten pushed back as another more pressing
project has come in for me to work on so I haven't had a chance to try this
out yet. Thanks for the links though which I have saved and I will
certainly look them over closer when I can get back to this.

Ryan
 
S

Steven Cheng[MSFT]

Sure Ryan,

Please feel free to post here when you meet further problem on this issue
later or let me know if you got any progress.

Good luck!

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
C

Cor Ligthert [MVP]

Steven,
var img = document.getElementById("imgTitle");
img.src = "new image url";
I thought as well on that solution, problem with is, that you have to know
the name of the image (it cannot have the same name because than it will get
it again from cache). You don't know that name, therefore you see in my
sample that removing from cache from the page where the image is in. (At
least I cannot remove a single image from cache in using a webpage).

:)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top