在确定的日期和时间开始流程 [英] Start Process in a determinated Day and Time

查看:61
本文介绍了在确定的日期和时间开始流程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个客户端/服务器应用程序,它将与备份程序(Cobian)连接。



在服务器上我有一个列表框,其中写有连接到它的客户端的名称和IP地址。



双击客户端出现在列表框中我会看到一个窗口,我可以在其中选择我想要备份的日期和时间。



日期和时间都保存在文本中具有以下语法的文件:MON TUE; 11



问题:



通过任务调度程序,我需要在文本文件的日期和时间内启动Cobian程序。



你能帮助我吗?







让我解释一下,此刻我有这段代码:



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?



Let me explain, in this moment I have this code:

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));





我想有一些东西可以让我有机会代替DaysOfTheWeek.AllDays,就像天[0] .ToString ()。



你明白吗?

[/编辑]







最后我选择了这种方式:





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:

//------------- 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 -------------





我的代码基于此 TaskScheduler [ ^ ]

推荐答案

查看答案在其中 [ ^ ]。



其中一个参考这篇文章 [ ^ ]。





WeeklyTrigger.DaysOfWeek [ ^ ]提供每日的个人值。使用适当的一个而不是 AllDays



但这里没有 ToString()

[/ Edit]
Have a look at the answers here[^].

One of them references this article[^].


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

But no ToString() here.
[/Edit]


这篇关于在确定的日期和时间开始流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆