Click here to Skip to main content
16,015,504 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone,

I've a client/server application that will interface with a backup program (Cobian).

On the server I have a listbox where are written name and IP address of the client connected to it.

Double-clicking on the client present in the listbox I get a window where I can select the days and time in which I want the backups are made.

Days and time are are saved in a text file with this syntax: MON TUE ;11

Question :

Through a task scheduler I need to start the program Cobian only on the days and time taken from the text file.

Can you help me?


[Edit]
Let me explain, in this moment I have this code:

C#
using System;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32.TaskScheduler;

//------------- TASK SCHEDULER: -----------------

string[] Paths = Directory.GetFiles(Environment.CurrentDirectory, "*.ini");

foreach (string path in Paths) 
{
    StreamReader sr = new StreamReader(path);
                
    string[] name_pc = sr.ReadLine().Split(':');
    string[] ip = sr.ReadLine().Split(':');
    string[] temp = sr.ReadLine().Split(';');
    string[] hour = temp[temp.Length-1].Split(':');
    string[] days= temp[0].Substring(0, temp[0].Length - 1).Split(' ');
}
    TaskService ts = new TaskService();
    TaskDefinition td = ts.NewTask();
    td.Triggers.Add(new WeeklyTrigger(DaysOfTheWeek.AllDays, 2));


I would like to have something that would give me the possibility to insert in place of DaysOfTheWeek.AllDays something like days[0].ToString().

Do you understand?
[/Edit]



At the end I chose this way:

C#
//------------- TASK SCHEDULER: -----------------

            string[] Paths = Directory.GetFiles(Environment.CurrentDirectory, "*.ini"); //Prende il percorso di tutti i file nella cartella corrente del programma con estensione .ini

            foreach (string path in Paths) //Ogni file con estensione .ini viene letto e viene isolato soltanto l'indirizzo ip
            {

                StreamReader sr = new StreamReader(path);

                string[] nome_pc = sr.ReadLine().Split(':');
                string[] ip = sr.ReadLine().Split(':');
                string[] temp = sr.ReadLine().Split(';');
                string[] ore = temp[temp.Length - 1].Split(':');
                string[] giorni = temp[0].Substring(0, temp[0].Length - 1).Split(' ');
                string[] days = { "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };

                TaskScheduler.TriggerItem triggerItem = new TaskScheduler.TriggerItem();

                triggerItem.Tag = nome_pc[1].ToString() + ";" + ip[1].ToString(); //Prende il nome del pc + l'indirizzo ip
                triggerItem.StartDate = DateTime.Today; //Prende la data di oggi
                triggerItem.EndDate = DateTime.Today.AddYears(80); //Termina tra ottant'anni a partire dal 2013
                triggerItem.TriggerTime = Convert.ToDateTime(ore[0].ToString() + ":00:00");

                for (byte day = 0; day < 7; day++)
                {
                    if (Array.IndexOf(giorni, days[day]) != -1) //Restituisce la posizione del relativo giorno
                    {
                        triggerItem.TriggerSettings.Weekly.DaysOfWeek[day] = true;
                    }
                }

                triggerItem.Enabled = true; 
                _taskScheduler.AddTrigger(triggerItem);
                _taskScheduler.Enabled = true; // Fa partire il task scheduler

                Send_To(ip[1].ToString(), "ESEGUI");
                sr.Dispose();
                sr.Close();
                //  ------------- END TASK SCHEDULER -------------


My code is based on this TaskScheduler[^]
Posted
Updated 29-Aug-13 3:59am
v3
Comments
lukeer 28-Aug-13 6:16am    
Where exactly is the problem?
Transferring the time stamp to the client?
Receiving the time stamp at the client?
Scheduling for the given time stamp?
Starting the target application?
Nicola M 28-Aug-13 6:26am    
My problem is how to do a task scheduler that start Cobian only on the days and at the hour taken from the text file.
lukeer 29-Aug-13 6:08am    
I updated my solution.

1 solution

Have a look at the answers here[^].

One of them references this article[^].

[Edit]
The WeeklyTrigger.DaysOfWeek[^] provide for individual values per day. Use the appropriate one instead of AllDays.

But no ToString() here.
[/Edit]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900