using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ConsoleApp1
{
    class Program
    {


        static void Main(string [] args) {

            // Create an array of Thread references.
            int numThread = Convert.ToInt32(args[0].ToString());
            Thread[] array = new Thread[numThread];
            for (int i = 0; i < array.Length; i++)
            {
                // Start the thread with a ThreadStart.
                ThreadStart start = new ThreadStart(Start);
                array[i] = new Thread(start);
                array[i].Start();
            }
            // Join all the threads.
            for (int i = 0; i < array.Length; i++)
            {
                array[i].Join();
            }
            Console.WriteLine("DONE");

        }
        static void Start()
        {
            // This method has no formal parameters.
            Console.Write("Start - ");
            GestorePDF.Logic.ThreadManager gp = new GestorePDF.Logic.ThreadManager();
            int maxGestoreThreads = int.Parse(ConfigurationManager.AppSettings["maxGestoreThreads"]);
            int limit = int.Parse(ConfigurationManager.AppSettings["gestoreThreadsLimit"]);
            if (limit < maxGestoreThreads) maxGestoreThreads = limit;
            gp.Main(maxGestoreThreads);

        }
        //static void Main(string[] args)
        //{


        //        // Start a thread that calls a parameterized static method.
        //        Thread newThread = new Thread(Program.DoWork);
        //        newThread.Start(42);

        //    // Start a thread that calls a parameterized instance method.
        //        Program w = new Program();
        //        newThread = new Thread(w.DoMoreWork);
        //        newThread.Start( "The answer.");



        //    try
        //    {
        //        //GestorePDF.Logic.ThreadManager gp = new GestorePDF.Logic.ThreadManager();
        //        //int maxGestoreThreads = int.Parse(ConfigurationManager.AppSettings["maxGestoreThreads"]);
        //        //int limit = int.Parse(ConfigurationManager.AppSettings["gestoreThreadsLimit"]);
        //        //if (limit < maxGestoreThreads) maxGestoreThreads = limit;
        //        //gp.Main(maxGestoreThreads);

        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine("Errore regerico :" + ex.Message.ToString());
        //    }

        //}
        //public static void DoWork(object data)
        //{
        //    Console.WriteLine("Static thread procedure. Data='{0}'",
        //        data);
        //    GestorePDF.Logic.ThreadManager gp = new GestorePDF.Logic.ThreadManager();
        //    int maxGestoreThreads = int.Parse(ConfigurationManager.AppSettings["maxGestoreThreads"]);
        //    int limit = int.Parse(ConfigurationManager.AppSettings["gestoreThreadsLimit"]);
        //    if (limit < maxGestoreThreads) maxGestoreThreads = limit;
        //    gp.Main(maxGestoreThreads);

        //}

        //public void DoMoreWork(object data)
        //{
        //    Console.WriteLine("Instance thread procedure. Data='{0}'",
        //        data);
        //}

    }
}