-3

Web ページを 1 時間ごとにチェックするスクリプトをコーディングしたいと考えています。私はSOに関する他の質問を見てきましたが、誰もが使用について話している:

static System.Windows.Forms.Timer t;

誰か助けてくれませんか?

最近は Unix と Linux を見ているので、長い間 C# でコーディングをしていませんでした。

どんな助けでも大歓迎です。

4

1 に答える 1

5
using System;
using System.Net;
using System.Timers;

class Program
{
    static void Main()
    {
        Timer t = new Timer(TimeSpan.FromHours(1).TotalMilliseconds);
        t.Elapsed += (sender, e) =>
        {
            // This code will execute every hour
            using (var client = new WebClient())
            {
                // Send an HTTP request to download the contents of the web page
                string result = client.DownloadString("http://www.google.com");

                // do something with the results
                ...
            }
        };
        Console.WriteLine("press any key to stop");
        Console.ReadKey();
    }
}
于 2012-08-16T12:13:19.850 に答える