<commit_before>﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace VKDiscordBot.Models
{
    public class RepetitiveTask
    {
        /// <summary>
        /// Возвращает id повторяющиеся задачи RepetitiveTask
        /// </summary>
        public event Action<int> TaskStarted;

        public event Action<TaskStatus> TaskEnded;

        public Action Action { get; private set; }

        public int DueTime { get; private set; }

        public int Period { get; private set; }

        public RepeririveTaskState State { get; private set; }

        public int Id
        {
            get
            {
                return _timer.GetHashCode();
            }
        }

        private Timer _timer;

        public RepetitiveTask(Action action, int dueTime, int period)
        {
            State = RepeririveTaskState.TimerStopped;
            DueTime = dueTime;
            Period = period;
            Action = action;
            TaskStarted += (id) => State = RepeririveTaskState.TaskStarted;
            TaskEnded += (status) =>
            {
                if (State != RepeririveTaskState.TimerStopped)
                {
                    State = RepeririveTaskState.WaitingTimerTrip;
                }
            };
            _timer = new Timer((sender) =>
            {
                TaskStarted?.Invoke(Id);
                Task.Factory.StartNew(action).ContinueWith((s) => 
                {
                    TaskEnded?.Invoke(s.Status);
                });
            }, null, Timeout.Infinite, Timeout.Infinite);                      
        }

        public void Start()
        {
            _timer.Change(DueTime, Period);
            State = RepeririveTaskState.WaitingTimerTrip;
        }

        public void Stop()
        {
            _timer.Change(Timeout.Infinite, Timeout.Infinite);
            State = RepeririveTaskState.TimerStopped;
        }

        public void Change(int dueTime, int period)
        {<commit_msg>Added task id in TaskEnded event<commit_after>﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace VKDiscordBot.Models
{
	public class RepetitiveTask
    {
        public event Action<int> TaskStarted;

        public event Action<int, TaskStatus> TaskEnded;

        public Action Action { get; private set; }

        public int DueTime { get; private set; }

        public int Period { get; private set; }

        public RepeririveTaskState State { get; private set; }

        public int Id
        {
            get
            {
                return _timer.GetHashCode();
            }
        }

        private Timer _timer;

        public RepetitiveTask(Action action, int dueTime, int period)
        {
            State = RepeririveTaskState.TimerStopped;
            DueTime = dueTime;
            Period = period;
            Action = action;
            TaskStarted += (id) => State = RepeririveTaskState.TaskStarted;
            TaskEnded += (id, status) =>
            {
                if (State != RepeririveTaskState.TimerStopped)
                {
                    State = RepeririveTaskState.WaitingTimerTrip;
                }
            };
            _timer = new Timer((sender) =>
            {
                TaskStarted?.Invoke(Id);
                Task.Factory.StartNew(action).ContinueWith((s) => 
                {
                    TaskEnded?.Invoke(s.Id,s.Status);
                });
            }, null, Timeout.Infinite, Timeout.Infinite);                      
        }

        public void Start()
        {
            _timer.Change(DueTime, Period);
            State = RepeririveTaskState.WaitingTimerTrip;
        }

        public void Stop()
        {
            _timer.Change(Timeout.Infinite, Timeout.Infinite);
            State = RepeririveTaskState.TimerStopped;
        }

        public void Change(int dueTime, int period)
        {
{'fraction_non_alphanumeric': 0.08471593765711413, 'fraction_numerical': 0.0, 'mean_word_length': 1.4946708463949843, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6703046', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1030, 'n_words': 232}