Three Timers in .NET and "Timer" in the web page

xiaoxiao2021-03-06  43

Three Timers in .NET and "Timer" in the web page

.NET Framework provides three timers, namely:

System.Timers.Timer Based on the server's timer, on the "Component" tab of the Toolbox; System.Windows.Forms.Timer Based on Windows-based standard timer, located in the "Windows Form" option of "Toolbox" On the card; System.Threading.Timer can only be used when programming.

There are three types of timers, see your Visual Studio .NET document (location: Visual Studio .NET - Visual Basic and Visual C # .NET - Using Component Programming - Create File System and Timer Components - Based on Server-based Timers Introduction.

I have written: Using Timer in ASP.NET mainly lists an example of using System.Timers.Timer in an ASP.NET application (notice is not web form).

Some netizens wrote this example into Web Form. After the test failed, my blog "vented" grievances, I can understand, but if some people are too "quite horizontal", there is too difficult to accept.

The web page is originally different from the Windows program, and the web page is mostly like the "request" of the C / S structure - "Answer" model (actually like this). Such "request" and "response" are to pay attention to efficiency: can't say that you "request" is over, the server first "rest" 1 minute, then "answer" you; if so, do you go to your site?

Although Microsoft spent a lot of effort to make Web form "look" very like Windows Form, it can't change the spirit of the web page, so the idea of ​​placing the timer in the web form is childish.

In fact, I can understand that the actual needs of several netizens are: letting the webpage refreshed, or what to do. Can you please pay attention, where is the "timing" happened? Is the server side? No, it is "timed" in the user's client, is the "timing" of the user browser of your page!

The code written by the C # / VB.NET code in the ASP.NET program is executed at the server. So the three timers provided by .NET Framework can not meet your needs! How to use the server "Timer" when the client's "timer" is used?

The client's "timing" is to solve with the client means. The Window object in the HTML DOM model has a SetTimeout method, which can help you implement the client you want.

BTW, for example, you want the visitor to see a warning box, this action also happens in the client, so it is still using the client means (such as the alert method of the Window object in HTML DOM), not .NET Msgbox.show in C # / VB.NET code (if this will display a warning box on the server, do you want to warn the Administrator?).

Turning back, that article, although the timer cannot be used in the web form, but it is possible in the ASP.NET application.

All pages in the ASP.NET site form a web application, this program is running on the server, stores information, SESSION, and other information. When the web application starts from the server, the application_onstart; the application ends (server shutdown, restart), will trigger Application_Onnd; receive new client "request", Application_BeginRequest; ... This is a continuous process. (Generally, these code can be written in the code file of the global.asax) we can use "timer" in this process. Of course, it should be based on a server-based timer, System.Timers.Timer type. Requirements asked by netizens such as YMM and Daniel (Timed Data from the Database) can be implemented by methods in the text:

Start the timer in your application_onstart, write your "Generate Static Page" from the Database Data Data in the Elaspsed event handler.

Published in Saturday, August 21, 2004 1:49 PM

comment

#re: .NET's three Timer and "Timer" in the web page seem to have this article in Yao Dong's article.

8/21/2004 2:21 PM |

Happily

#re: .NET in the three Timer and "Timer" in the web page

http://blog.joycode.com/yaodong/articles/25845.aspx

Yao Dong's article, I didn't see it. He mainly wrote the difference between the three counters of .NET Framework.

I mainly tell me the misunderstanding of the previous article, and explain the Web Form

Timer's inconsistent.

8/21/2004 2:28 pm |

Treasure

#re: .NET, "Timer" in the page in .NET, in fact, the end is some misunderstandings for the web model, and it is of course brought some of the ideas of the Windows program to the web, so it has caused misunderstandings. . .

8/21/2004 4:13 PM |

cnlamar

#re: The three Timers in .NET and the "Timer" client in the web page can use JS:

SetTimeout ("Fntime ()", 1000);

8/22/2004 10:58 AM |

Baoyu

#re: .NET in the three Timer and "Timer" in the web page are misunderstood ,,, I have obedited. . .

I don't have JS recently, huh, huh, my smartphone does not support.

8/23/2004 9:51 am |

Tommywoo

#re: The three Timer in .NET and "Timer" MessageBox in the web page can be used in ASP.NET.

And a window is prompted in the client.

8/26/2004 7:43 PM |

Cold maple

#re: .NET, "Timer", "Timer" in the page, I found a strange phenomenon, which is the code of the landlord; when it is implemented with C #, but I changed to the file after reading and writing. It's really depressed.

8/27/2004 12:50 PM |

Xuxiaoping

#re: The three Timer in .NET and "Timer" to Xuxiaoping in the web page:

It may be that the permissions of the operation file are not enough, please check the NTFS permissions of the directory. You can put the code of the read and write file in Web Form; if you read and write success, put it in Global as a timing event.

To Hanfei Taste:

What are you talking about by the client HTML DOM (or usually what JavaScript)? If you are messagebox in server code, please have an example? ......

8/27/2004 12:59 PM |

Treasure

#re: The three Timers in .NET and "Timer" in the web page create new

If you thread, you can't read the contents of the current page? So in this way

8/27/2004 1:08 pm |

Furrosoft

#re: The three Timers in .NET and "Timer" to FuCrosoft in the web page:

The code is written in global.asax, where is the "current page"?

Your true thoughts are: "Save the contents of a * .aspx page to static * .html"? Is that right?

If so, of course, it is also possible, but it is not as simple as you think.

(Coordination is: Using the class in System.NET, simulate an HttpRequest to the ASPX, write the obtained httpResponse to the file. But it is not as good as another idea: directly read data directly from the database, then use StringBuilder "Patchwork "String that is consistent with the * .aspx page, written directly to * .html files. This will be higher than the former running efficiency, although it may be slightly troublesome.)

Don't think about the tartles all day, and many times when you can't solve the problem.

8/30/2004 9:26 am |

Treasure

#re: .NET in the three Timer and "Timer" in the web page adds to the Timer in a normal ASPX web page, cannot be redirected in the Elaspsed event.

11/7/2004 9:56 PM |

Blackhorse

#re: The three Timer in .NET and "Timer" to Blackhorse in the web page:

I emphasized in my article: I can't use it in Web Forms (which is what you said.

Timer.

11/8/2004 9:15 AM |

Treasure

#re: .NET's Timer and the "Timer" in the web page I want to write a chat page in the server, and the client has a substantially two functions when accessing this page:

Display chat content and send chat words, where chat content is read from the server's database.

The problem now is that the page opens on the client can be used to read the latest data from the server, but do not refresh the entire page.

(Because the part is sent, if you add:

),

How to achieve it? use

Can TIMER can be implemented? This problem is bothered for a long time, which brother can give some comments?

11/15/2004 5:02 PM |

Slelotus

#re: .NET's Timer and "Timer" in the web page can help me implement automatic submission function in ASP.NET! ! With ASP.NET, don't js

11/22/2004 5:13 PM |

Sun

#re: The three Timer in .NET and "Timer" to Broad Treasures in the webpage:

I said it is indeed the server:

Messagebox.show ();

If you are in ASP.NET, you can pop up Messagebox on the client, just, the pops coming out of the window is not very good. The pop-up window is indeed a Windows window.

In this case, online, you can find it yourself.

The MessageBox's Show method has a signature to achieve this. I said it is absolutely not a Alert in JS.

12/13/2004 12:56 PM |

Cold maple

#re: The three Timer in .NET and "Timer" to Hanmei Temperature in the webpage:

May wish to post an example? Or give a connection?

Otherwise I will not believe it.

12/13/2004 1:17 PM |

Treasure

#re: The three Timer in .NET and "Timer" in the web page can help me implement automatic submission function in ASP.NET! ! With ASP.NET, don't js

12/15/2004 11:41 am |

JBBJCC

# 关于. 计 计 计 b 来自 来自: blog.9cbs.net

12/20/2004 5:46 PM |

Leisang

#re: .NET in the three Timer and the "Timer" of the webpage, is not this:

http://www.mono-software.com/desktopdefault.aspx?tabid=244&tabindex=4

12/27/2004 11:07 am |

LZP

#re: The three Timer in .NET and "Timer" to LZP in the web page:

You said this is really a good seal, which can be used as convenient as other controls. But in the final analysis, it is also achieved by JavaScript DHTML. If you don't believe it, you can look at the HTML source code it generated ... Of course, this can be called ASP.NET server control, because almost all server controls are packaged. JavaScript DHTML implements a specific effect.

If you don't understand the wrong, the meaning of cold maple should be to say that in the ASP.NET server-side code, use the System.WindowsForms.MessageBox this Windows Form Control to display the message box. But I think it is impossible unless he can give an example or give the relevant information link.

12/28/2004 9:31 AM |

Treasure

Post Comment

转载请注明原文地址:https://www.9cbs.com/read-65259.html

New Post(0)