2012-04-26 122 views
0

我想每30分鐘運行一段代碼。在Windows任務計劃程序 - >創建任務 - >操作 - >新 - 有一個地方插入一個腳本/程序。 我的問題什麼樣的項目,我需要創建添加我的程序,以及我需要添加什麼樣的文件 - DLL?在Windows任務計劃程序中安排一個c#程序

我希望每30分鐘運行一段30行代碼,然後從網絡獲取內容,處理它並將其插入數據庫。

謝謝。

+0

我真的不關心它是什麼,我想這可能是一個exe .. – Nir 2012-04-26 14:39:06

回答

3

任務計劃程序運行普通的EXE。

你不需要做任何特殊的事情。

+1

但要記住的是,EXE將運行,但不可見,因此,如果你觸發例如WinForm應用程序你贏了」不要看錶格。 – Dan 2012-04-26 14:33:06

+2

@Dan:這取決於您將任務設置爲哪個用戶。 – SLaks 2012-04-26 14:33:59

3
using System; 
    using Microsoft.Win32.TaskScheduler; 

    class Program 
    { 
    static void Main(string[] args) 
    { 
    // Get the service on the local machine 

    using (TaskService ts = new TaskService()) 
    { 

    // Create a new task definition and assign properties 
     TaskDefinition td = ts.NewTask(); 
     td.RegistrationInfo.Description = "Does something"; 

     // Create a trigger that will fire the task at this time every other day 
     td.Triggers.Add(new DailyTrigger { DaysInterval = 2 }); 

     // Create an action that will launch Notepad whenever the trigger fires 
     td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null)); 

     // Register the task in the root folder 
     ts.RootFolder.RegisterTaskDefinition(@"Test", td); 

     // Remove the task we just created 
     ts.RootFolder.DeleteTask("Test"); 
     } 
    } 
    } 
相關問題