using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JobReportMailService
{
    public partial class fChildBase : Form
    {
        protected Boolean taskrun = true;
        protected DateTime ChkMakeSchDayWeekTime;
        protected DateTime ConsoleTime;
        protected Task task = null;
        protected int Delaytime = 60000;
        protected Boolean taskwait = true;

        public fChildBase()
        {
            InitializeComponent();
            ChkMakeSchDayWeekTime = DateTime.Now.AddDays(-1);
            ConsoleTime = ChkMakeSchDayWeekTime;            
        }

        private void fChildBase_Load(object sender, EventArgs e)
        {
            //taskwait = Pub.debugmode;
        }

        protected void addmsg(string m)
        {
            if (this.richTextBox1.InvokeRequired)
            {
                this.richTextBox1.BeginInvoke(new Action(() =>
                {
                    if (this.richTextBox1.Lines.Length > 1000) this.richTextBox1.Clear();
                    this.richTextBox1.AppendText(DateTime.Now.ToString("HH:mm:ss.fff") + "] " + m + "\n");
                    this.richTextBox1.ScrollToCaret();
                }));
                return;
            }
            if (this.richTextBox1.Lines.Length > 1000) this.richTextBox1.Clear();
            this.richTextBox1.AppendText(DateTime.Now.ToString("HH:mm:ss.fff") + "] " + m + "\n");
            this.richTextBox1.ScrollToCaret();
        }

        private void fChildBase_FormClosed(object sender, FormClosedEventArgs e)
        {
            if(this.task != null)
            {
                taskwait = true;
                taskrun = false;
                task.Wait(1000);
                try
                {
                    task.Dispose();
                }
                catch (Exception ex)
                {
                    
                }
            }
        }
    }
}
