X
X
Xveeder2018-07-18 19:53:52
C++ / C#
Xveeder, 2018-07-18 19:53:52

How to create a task manager in C#?

Good day, friends.
Suppose there is a program that has many independent functions.
For example: get information from the server, create a data file, generate an image.
The task is as follows: you need to create a dynamic list of tasks that can be run en masse. I select the desired function, fill out the form, connect all the necessary resources, then save this function to the task. Then I do the same with the rest.
After saving, these functions converted into tasks appear as a list in the task manager. In the task manager, this list of tasks must be launched for execution in the queue in which they are placed in the task manager
Suppose that when creating a task, you can write the task data to a file with XML / JSON, and then parse them when opening the task manager, but I can’t figure out how to start a series of sequential tasks based on them.
Please show me which way to look.
Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
OnYourLips, 2018-07-18
@OnYourLips

The task is very simple, you just need to be able to calculate the time to start and run processes.
There are also a lot of libraries for both tasks on the github.

G
GavriKos, 2018-07-18
@GavriKos

Well, obviously there should be a common config in the same json, which indicates which configs / tasks to run. Each task inherits from one interface and can talk about its completion.
It is not entirely clear where and how all this should be spinning, so maybe something like jenkins or analogues will suit you.

S
Satangelus, 2018-07-19
@Satangelus

I don't understand the difficulty. In theory, you need to start a timer with a certain step and follow the timer to perform the check procedure, it’s not time to start tasks. Then, if it's time, we create a thread, read the order of starting tasks and run the Process.Start () process, check the status of the process while the process is alive, do yield () when the process is completed, go to the next one in the list and repeat until the list is exhausted.
https://metanit.com/sharp/tutorial/11.9.php
https://metanit.com/sharp/tutorial/18.1.php

A
Alexey Makarenya, 2018-07-21
@makarenya

using System;
using System.Collections.Generic;

// Давайте договоримся, что для нас не имеет значения,
// как именно сохранены данные. Это может быть json, xml
// А может оказаться что это БД или бинарнас сериализация
// Главное, что данные можно получить через вот этот интерфейс
public interface IDataRecord {
  // Возвращает какое-нибудь свойство запуска
  // Это может быть путь к паке или там количество итераций
  // С точки же зрения xml или json - это значение аттрибута 
  // с именем name
  string Get(string name);
}

// А вот этот интерфейс содержит те методы, которые нам надо вызывать
public interface IProcessor
{
  void MakeChildrenHappy(int numberOfCandys, bool haveClown, string place);
  void BeatAllJedis(string weapoonName, bool killThem, int timeout);
}
          
public class Program
{
  public static void Main()
  {
    var taskList = LoadTasks();
    var processor = CreateProcessor();
    foreach(var task in taskList) 
    {
      var type = task.Get("type");
      switch(type)
      {
        case "make_children_happy":
          RunMakeChildrenHappy(processor, task);
          break;
        case "beat_all_jedis":
          RunBeatAllJedis(processor, task);
          break;
      }
    }
  }
  
  public static void RunMakeChildrenHappy(IProcessor processor, IDataRecord task)
  {
    var numberOfCandys = int.Parse(task.Get("number_of_candys"));
    var haveClown = bool.Parse(task.Get("have_clown"));
    var place = task.Get("place");
    processor.MakeChildrenHappy(numberOfCandys, haveClown, place);
  }
  
  public static void RunBeatAllJedis(IProcessor processor, IDataRecord task)
  {
    var weapoonName = task.Get("weapoon_name");
    var killThem = bool.Parse("kill_them");
    var timeout = int.Parse("timeout");
    processor.BeatAllJedis(weapoonName, killThem, timeout);
  }

  public static List<IDataRecord> LoadTasks() 
  {
    // TODO: на самом деле мы тут подгружает json или xml, или из БД читаем
    // Но пример то не про форматы сохранения.
    return null;
  }
  
  public static IProcessor CreateProcessor()
  {
    // TODO: Ну а тут мы создаём класс, который реализует методы, которые 
    // нам надо вызывать
    return null;
  }
  
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question