You can search online materials and test it on your own to meet your needs. If you find any problem, please point it out. Thank you.
The function of the case: automatically open the Baidu website around every day.
Main Code:
1. Global. asax File
[Cpp]
Void Application_Start (object sender, EventArgs e)
{
OpenBaiDu. Execute ();
}
Void Application_Start (object sender, EventArgs e)
{
OpenBaiDu. Execute ();
}
2. OpenBaiDu static class file
[Csharp]
Public static class OpenBaiDu
{
Public static bool IsOpen = false;
Public static DateTime LastOpenTime = DateTime. Now;
Public static DateTime OpenTime = DateTime. Today. AddHours (10 );
Public static void Execute ()
{
Timer objTimer = new Timer ();
ObjTimer. Interval = 1000; // The unit of time is millisecond. For example, if the value is 10 seconds, the value is 10000.
ObjTimer. Enabled = true;
ObjTimer. Elapsed + = new ElapsedEventHandler (objTimer_Elapsed );
}
Public static void objTimer_Elapsed (object sender, ElapsedEventArgs e)
{
// If the last execution time is yesterday, set IsOpen to false, indicating that the task has not been executed today.
If (DateTime. Today. AddDays (-1) = LastOpenTime. Date)
{
IsOpen = false;
}
// If the task is not executed today and the current time is later than the specified execution time,
// After the execution is complete, set IsOpen to true, indicating that it has been executed today.
If (! IsOpen & DateTime. Now> = OpenTime)
{
System. Diagnostics. Process. Start ("http://www.baidu.com ");
IsOpen = true;
OpenTime = DateTime. Today;
}
}
}
Public static class OpenBaiDu
{
Public static bool IsOpen = false;
Public static DateTime LastOpenTime = DateTime. Now;
Public static DateTime OpenTime = DateTime. Today. AddHours (10 );
Public static void Execute ()
{
Timer objTimer = new Timer ();
ObjTimer. Interval = 1000; // The unit of time is millisecond. For example, if the value is 10 seconds, the value is 10000.
ObjTimer. Enabled = true;
ObjTimer. Elapsed + = new ElapsedEventHandler (objTimer_Elapsed );
}
Public static void objTimer_Elapsed (object sender, ElapsedEventArgs e)
{
// If the last execution time is yesterday, set IsOpen to false, indicating that the task has not been executed today.
If (DateTime. Today. AddDays (-1) = LastOpenTime. Date)
{
IsOpen = false;
}
// If the task is not executed today and the current time is later than the specified execution time,
// After the execution is complete, set IsOpen to true, indicating that it has been executed today.
If (! IsOpen & DateTime. Now> = OpenTime)
{
System. Diagnostics. Process. Start ("http://www.baidu.com ");
IsOpen = true;
OpenTime = DateTime. Today;
}
}
}