none
Auto run windows application RRS feed

  • Question

  • How to run an application automatically after a particular time interval using C#.net code. Plz help..its very urgent

    Mrs Nishad


    • Edited by Mrs Nishad Friday, February 14, 2020 3:54 AM
    Friday, February 14, 2020 3:53 AM

All replies

  • The system Task Scheduler application, included in Windows, is probably able to perform such tasks.

    See the Create Task dialog, Triggers tab, New, etc.

    Friday, February 14, 2020 6:28 AM
  • i want to use C# code for automatically running the application... 

    Mrs Nishad

    Friday, February 14, 2020 7:24 AM
  • Plz help...

    Mrs Nishad

    Saturday, February 15, 2020 7:17 AM
  • I don't know what you're expecting.  You can use a System.Timer to have an event fire at some point in the future, and that event handler can use System.Diagnostics.Process to launch a process.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Saturday, February 15, 2020 7:43 AM
  • For example, this test creates a Task which launches Notepad every 1 minute =>

    // To check the task : "C:\WINDOWS\system32\mmc.exe" "C:\WINDOWS\system32\taskschd.msc" /s
    
    // Add reference to : TaskScheduler 1.1 Type Library
    // Add : using TaskScheduler;
    ITaskService ts = new TaskScheduler.TaskScheduler();
    try
    {                        
        ts.Connect(null, null, null, null);
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show("Error: " + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }
    ITaskDefinition td = ts.NewTask(0);
    td.RegistrationInfo.Author = "Author test";
    td.RegistrationInfo.Description = "Task Description";
    
    ITimeTrigger tt = (ITimeTrigger)td.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_TIME);
    tt.Enabled = true;
    tt.StartBoundary = (DateTime.Now.AddSeconds(60)).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
    tt.Repetition.Interval = "PT1M";
    td.Settings.MultipleInstances = _TASK_INSTANCES_POLICY.TASK_INSTANCES_PARALLEL;
    
    IExecAction execAction = (IExecAction)td.Actions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC);
    execAction.Path = @"c:\windows\notepad.exe";
    var rootFolder = ts.GetFolder("\\");
    try
    {
        IRegisteredTask ticket = rootFolder.RegisterTaskDefinition("MyTask", td, (int)_TASK_CREATION.TASK_CREATE_OR_UPDATE, null, null, _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN, null);
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show("Could not add a task : " + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return;
    }

    • Proposed as answer by EckiS Saturday, February 15, 2020 6:39 PM
    Saturday, February 15, 2020 3:41 PM
  • Hi,

    Has your problem been solved?

    If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Timon



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 18, 2020 6:47 AM