[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

C# MultiThreading Simultaneous File Copy Code Review Windows Service

Posted on 2008-06-25
3
Medium Priority
?
2,412 Views
Last Modified: 2008-06-27
I have a C# windows service application that copies 48 images from the security camera folder to a backup drive every 3 seconds between 6:30 AM and 6:00 PM Monday through Friday.  Thats 3,312,000 images per week.  I used multi-threading because going through a for loop didn't copy the 48 images within 3 seconds.  The code works fine but since is my first real C# application I would like someone to look it over and let me know if it I could simplify it more.  I am probably doing extra steps because I don't know all the in's and out's of C# yet.  Also could you check and see if my code will cause any memory leaks.  The attached code is from Service1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.IO;
using System.Threading;
 
namespace myFileCopyService
{
    public partial class Service1 : ServiceBase
    {
        string[,] cam = new string[48, 2];
        public Service1()
        {
            InitializeComponent();
        }
 
        protected override void OnStart(string[] args)
        {
            timer1.Enabled = true;
 
            cam.SetValue("CAM01", 0, 0); cam.SetValue("CS07", 0, 1);
            cam.SetValue("CAM02", 1, 0); cam.SetValue("CS07", 1, 1);
            cam.SetValue("CAM03", 2, 0); cam.SetValue("CS07", 2, 1);
            cam.SetValue("CAM04", 3, 0); cam.SetValue("CS07", 3, 1);
            cam.SetValue("CAM05", 4, 0); cam.SetValue("CS08", 4, 1);
            cam.SetValue("CAM06", 5, 0); cam.SetValue("CS08", 5, 1);
            cam.SetValue("CAM07", 6, 0); cam.SetValue("CS08", 6, 1);
            cam.SetValue("CAM08", 7, 0); cam.SetValue("CS08", 7, 1);
            cam.SetValue("CAM09", 8, 0); cam.SetValue("CS09", 8, 1);
            cam.SetValue("CAM10", 9, 0); cam.SetValue("CS09", 9, 1);
            cam.SetValue("CAM11", 10, 0); cam.SetValue("CS09", 10, 1);
            cam.SetValue("CAM12", 11, 0); cam.SetValue("CS09", 11, 1);
            cam.SetValue("CAM13", 12, 0); cam.SetValue("CS10", 12, 1);
            cam.SetValue("CAM14", 13, 0); cam.SetValue("CS10", 13, 1);
            cam.SetValue("CAM15", 14, 0); cam.SetValue("CS10", 14, 1);
            cam.SetValue("CAM16", 15, 0); cam.SetValue("CS10", 15, 1);
            cam.SetValue("CAM17", 16, 0); cam.SetValue("CS11", 16, 1);
            cam.SetValue("CAM18", 17, 0); cam.SetValue("CS11", 17, 1);
            cam.SetValue("CAM19", 18, 0); cam.SetValue("CS11", 18, 1);
            cam.SetValue("CAM20", 19, 0); cam.SetValue("CS11", 19, 1);
            cam.SetValue("CAM21", 20, 0); cam.SetValue("CS12", 20, 1);
            cam.SetValue("CAM22", 21, 0); cam.SetValue("CS12", 21, 1);
            cam.SetValue("CAM23", 22, 0); cam.SetValue("CS12", 22, 1);
            cam.SetValue("CAM24", 23, 0); cam.SetValue("CS12", 23, 1);
            cam.SetValue("CAM25", 24, 0); cam.SetValue("CS01", 24, 1);
            cam.SetValue("CAM26", 25, 0); cam.SetValue("CS01", 25, 1);
            cam.SetValue("CAM27", 26, 0); cam.SetValue("CS01", 26, 1);
            cam.SetValue("CAM28", 27, 0); cam.SetValue("CS01", 27, 1);
            cam.SetValue("CAM29", 28, 0); cam.SetValue("CS02", 28, 1);
            cam.SetValue("CAM30", 29, 0); cam.SetValue("CS02", 29, 1);
            cam.SetValue("CAM31", 30, 0); cam.SetValue("CS02", 30, 1);
            cam.SetValue("CAM32", 31, 0); cam.SetValue("CS02", 31, 1);
            cam.SetValue("CAM33", 32, 0); cam.SetValue("CS03", 32, 1);
            cam.SetValue("CAM34", 33, 0); cam.SetValue("CS03", 33, 1);
            cam.SetValue("CAM35", 34, 0); cam.SetValue("CS03", 34, 1);
            cam.SetValue("CAM36", 35, 0); cam.SetValue("CS03", 35, 1);
            cam.SetValue("CAM37", 36, 0); cam.SetValue("CS04", 36, 1);
            cam.SetValue("CAM38", 37, 0); cam.SetValue("CS04", 37, 1);
            cam.SetValue("CAM39", 38, 0); cam.SetValue("CS04", 38, 1);
            cam.SetValue("CAM40", 39, 0); cam.SetValue("CS04", 39, 1);
            cam.SetValue("CAM41", 40, 0); cam.SetValue("CS05", 40, 1);
            cam.SetValue("CAM42", 41, 0); cam.SetValue("CS05", 41, 1);
            cam.SetValue("CAM43", 42, 0); cam.SetValue("CS05", 42, 1);
            cam.SetValue("CAM44", 43, 0); cam.SetValue("CS05", 43, 1);
            cam.SetValue("CAM45", 44, 0); cam.SetValue("CS06", 44, 1);
            cam.SetValue("CAM46", 45, 0); cam.SetValue("CS06", 45, 1);
            cam.SetValue("CAM47", 46, 0); cam.SetValue("CS06", 46, 1);
            cam.SetValue("CAM48", 47, 0); cam.SetValue("CS06", 47, 1);
 
        }
 
        protected override void OnStop()
        {
            timer1.Enabled = false;
        }
 
        private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            DateTime systemDate = DateTime.Now;
            DateTime startDate = DateTime.Today.AddHours(6.5D);
            DateTime endDate = DateTime.Today.AddHours(18D);
            int d = Convert.ToInt32(Convert.ToString((int)DateTime.Now.DayOfWeek + 1));
            if ((systemDate >= startDate) && (systemDate <= endDate))
            {
                if ((d == 1) | (d == 7))
                {
                    return;
                }
            }
            else
            {
                return;
            }
 
            string dy = "0"+Convert.ToString((int) DateTime.Now.DayOfWeek + 1);
            string hr = Right("0"+Convert.ToString(DateTime.Now.Hour),2);
            string mn = Right("0" + Convert.ToString(DateTime.Now.Minute), 2);
            string sc = Right("0" + Convert.ToString(DateTime.Now.Second), 2);
            string fn = @"\DY" + dy + @"\H" + hr + @"\H" + hr + "M" + mn + "S" + sc + ".jpg";
 
            try
            {
                string[,] Paths = new string[48, 2];
                for (int i = 0; i <= 47; i++)
                {
                    Paths[i, 0] = @"D:\Sec\CamFolder\LivePics\" + cam[i, 1] + "_" + cam[i, 0] + "_TEMP.jpg";
                    Paths[i, 1] = @"F:\CS\" + cam[i, 0] + fn;
                }
                FFC x01 = new FFC(); x01.pGF = Paths[1, 0]; x01.pST = Paths[1, 1]; Thread t01 = new Thread(new ThreadStart(x01.MethodFFC)); t01.Start();
                FFC x02 = new FFC(); x02.pGF = Paths[2, 0]; x02.pST = Paths[2, 1]; Thread t02 = new Thread(new ThreadStart(x02.MethodFFC)); t02.Start();
                FFC x03 = new FFC(); x03.pGF = Paths[3, 0]; x03.pST = Paths[3, 1]; Thread t03 = new Thread(new ThreadStart(x03.MethodFFC)); t03.Start();
                FFC x04 = new FFC(); x04.pGF = Paths[4, 0]; x04.pST = Paths[4, 1]; Thread t04 = new Thread(new ThreadStart(x04.MethodFFC)); t04.Start();
                FFC x05 = new FFC(); x05.pGF = Paths[5, 0]; x05.pST = Paths[5, 1]; Thread t05 = new Thread(new ThreadStart(x05.MethodFFC)); t05.Start();
                FFC x06 = new FFC(); x06.pGF = Paths[6, 0]; x06.pST = Paths[6, 1]; Thread t06 = new Thread(new ThreadStart(x06.MethodFFC)); t06.Start();
                FFC x07 = new FFC(); x07.pGF = Paths[7, 0]; x07.pST = Paths[7, 1]; Thread t07 = new Thread(new ThreadStart(x07.MethodFFC)); t07.Start();
                FFC x08 = new FFC(); x08.pGF = Paths[8, 0]; x08.pST = Paths[8, 1]; Thread t08 = new Thread(new ThreadStart(x08.MethodFFC)); t08.Start();
                FFC x09 = new FFC(); x09.pGF = Paths[9, 0]; x09.pST = Paths[9, 1]; Thread t09 = new Thread(new ThreadStart(x09.MethodFFC)); t09.Start();
                FFC x10 = new FFC(); x10.pGF = Paths[10, 0]; x10.pST = Paths[10, 1]; Thread t10 = new Thread(new ThreadStart(x10.MethodFFC)); t10.Start();
                FFC x11 = new FFC(); x11.pGF = Paths[11, 0]; x11.pST = Paths[11, 1]; Thread t11 = new Thread(new ThreadStart(x11.MethodFFC)); t11.Start();
                FFC x12 = new FFC(); x12.pGF = Paths[12, 0]; x12.pST = Paths[12, 1]; Thread t12 = new Thread(new ThreadStart(x12.MethodFFC)); t12.Start();
                FFC x13 = new FFC(); x13.pGF = Paths[13, 0]; x13.pST = Paths[13, 1]; Thread t13 = new Thread(new ThreadStart(x13.MethodFFC)); t13.Start();
                FFC x14 = new FFC(); x14.pGF = Paths[14, 0]; x14.pST = Paths[14, 1]; Thread t14 = new Thread(new ThreadStart(x14.MethodFFC)); t14.Start();
                FFC x15 = new FFC(); x15.pGF = Paths[15, 0]; x15.pST = Paths[15, 1]; Thread t15 = new Thread(new ThreadStart(x15.MethodFFC)); t15.Start();
                FFC x16 = new FFC(); x16.pGF = Paths[16, 0]; x16.pST = Paths[16, 1]; Thread t16 = new Thread(new ThreadStart(x16.MethodFFC)); t16.Start();
                FFC x17 = new FFC(); x17.pGF = Paths[17, 0]; x17.pST = Paths[17, 1]; Thread t17 = new Thread(new ThreadStart(x17.MethodFFC)); t17.Start();
                FFC x18 = new FFC(); x18.pGF = Paths[18, 0]; x18.pST = Paths[18, 1]; Thread t18 = new Thread(new ThreadStart(x18.MethodFFC)); t18.Start();
                FFC x19 = new FFC(); x19.pGF = Paths[19, 0]; x19.pST = Paths[19, 1]; Thread t19 = new Thread(new ThreadStart(x19.MethodFFC)); t19.Start();
                FFC x20 = new FFC(); x20.pGF = Paths[20, 0]; x20.pST = Paths[20, 1]; Thread t20 = new Thread(new ThreadStart(x20.MethodFFC)); t20.Start();
                FFC x21 = new FFC(); x21.pGF = Paths[21, 0]; x21.pST = Paths[21, 1]; Thread t21 = new Thread(new ThreadStart(x21.MethodFFC)); t21.Start();
                FFC x22 = new FFC(); x22.pGF = Paths[22, 0]; x22.pST = Paths[22, 1]; Thread t22 = new Thread(new ThreadStart(x22.MethodFFC)); t22.Start();
                FFC x23 = new FFC(); x23.pGF = Paths[23, 0]; x23.pST = Paths[23, 1]; Thread t23 = new Thread(new ThreadStart(x23.MethodFFC)); t23.Start();
                FFC x24 = new FFC(); x24.pGF = Paths[24, 0]; x24.pST = Paths[24, 1]; Thread t24 = new Thread(new ThreadStart(x24.MethodFFC)); t24.Start();
                FFC x25 = new FFC(); x25.pGF = Paths[25, 0]; x25.pST = Paths[25, 1]; Thread t25 = new Thread(new ThreadStart(x25.MethodFFC)); t25.Start();
                FFC x26 = new FFC(); x26.pGF = Paths[26, 0]; x26.pST = Paths[26, 1]; Thread t26 = new Thread(new ThreadStart(x26.MethodFFC)); t26.Start();
                FFC x27 = new FFC(); x27.pGF = Paths[27, 0]; x27.pST = Paths[27, 1]; Thread t27 = new Thread(new ThreadStart(x27.MethodFFC)); t27.Start();
                FFC x28 = new FFC(); x28.pGF = Paths[28, 0]; x28.pST = Paths[28, 1]; Thread t28 = new Thread(new ThreadStart(x28.MethodFFC)); t28.Start();
                FFC x29 = new FFC(); x29.pGF = Paths[29, 0]; x29.pST = Paths[29, 1]; Thread t29 = new Thread(new ThreadStart(x29.MethodFFC)); t29.Start();
                FFC x30 = new FFC(); x30.pGF = Paths[30, 0]; x30.pST = Paths[30, 1]; Thread t30 = new Thread(new ThreadStart(x30.MethodFFC)); t30.Start();
                FFC x31 = new FFC(); x31.pGF = Paths[31, 0]; x31.pST = Paths[31, 1]; Thread t31 = new Thread(new ThreadStart(x31.MethodFFC)); t31.Start();
                FFC x32 = new FFC(); x32.pGF = Paths[32, 0]; x32.pST = Paths[32, 1]; Thread t32 = new Thread(new ThreadStart(x32.MethodFFC)); t32.Start();
                FFC x33 = new FFC(); x33.pGF = Paths[33, 0]; x33.pST = Paths[33, 1]; Thread t33 = new Thread(new ThreadStart(x33.MethodFFC)); t33.Start();
                FFC x34 = new FFC(); x34.pGF = Paths[34, 0]; x34.pST = Paths[34, 1]; Thread t34 = new Thread(new ThreadStart(x34.MethodFFC)); t34.Start();
                FFC x35 = new FFC(); x35.pGF = Paths[35, 0]; x35.pST = Paths[35, 1]; Thread t35 = new Thread(new ThreadStart(x35.MethodFFC)); t35.Start();
                FFC x36 = new FFC(); x36.pGF = Paths[36, 0]; x36.pST = Paths[36, 1]; Thread t36 = new Thread(new ThreadStart(x36.MethodFFC)); t36.Start();
                FFC x37 = new FFC(); x37.pGF = Paths[37, 0]; x37.pST = Paths[37, 1]; Thread t37 = new Thread(new ThreadStart(x37.MethodFFC)); t37.Start();
                FFC x38 = new FFC(); x38.pGF = Paths[38, 0]; x38.pST = Paths[38, 1]; Thread t38 = new Thread(new ThreadStart(x38.MethodFFC)); t38.Start();
                FFC x39 = new FFC(); x39.pGF = Paths[39, 0]; x39.pST = Paths[39, 1]; Thread t39 = new Thread(new ThreadStart(x39.MethodFFC)); t39.Start();
                FFC x40 = new FFC(); x40.pGF = Paths[40, 0]; x40.pST = Paths[40, 1]; Thread t40 = new Thread(new ThreadStart(x40.MethodFFC)); t40.Start();
                FFC x41 = new FFC(); x41.pGF = Paths[41, 0]; x41.pST = Paths[41, 1]; Thread t41 = new Thread(new ThreadStart(x41.MethodFFC)); t41.Start();
                FFC x42 = new FFC(); x42.pGF = Paths[42, 0]; x42.pST = Paths[42, 1]; Thread t42 = new Thread(new ThreadStart(x42.MethodFFC)); t42.Start();
                FFC x43 = new FFC(); x43.pGF = Paths[43, 0]; x43.pST = Paths[43, 1]; Thread t43 = new Thread(new ThreadStart(x43.MethodFFC)); t43.Start();
                FFC x44 = new FFC(); x44.pGF = Paths[44, 0]; x44.pST = Paths[44, 1]; Thread t44 = new Thread(new ThreadStart(x44.MethodFFC)); t44.Start();
                FFC x45 = new FFC(); x45.pGF = Paths[45, 0]; x45.pST = Paths[45, 1]; Thread t45 = new Thread(new ThreadStart(x45.MethodFFC)); t45.Start();
                FFC x46 = new FFC(); x46.pGF = Paths[46, 0]; x46.pST = Paths[46, 1]; Thread t46 = new Thread(new ThreadStart(x46.MethodFFC)); t46.Start();
                FFC x47 = new FFC(); x47.pGF = Paths[47, 0]; x47.pST = Paths[47, 1]; Thread t47 = new Thread(new ThreadStart(x47.MethodFFC)); t47.Start();
            }
 
            catch (Exception exc)
            {
                Console.WriteLine("Exception "+exc.Message);
            }
 
        }
        static string Right(string s, int count)
        {
            string newString = String.Empty;
            if (s != null && count > 0)
            {
                int startIndex = s.Length - count;
                if (startIndex > 0)
                    newString = s.Substring(startIndex, count);
                else
                    newString = s;
            }
            return newString;
        }
    }
    public class FFC
    {
        public string pGF;
        public string pST;
        public void MethodFFC()
        {
            try
            {
                // Ensure that the target does not exist.
                File.Delete(pST);
 
                // Copy the file.
                File.Copy(pGF, pST);
                //Console.WriteLine("{0} copied to {1}", PathGetFrom, PathSaveTo);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
    }
 
}

Open in new window

0
Comment
Question by:ascnd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
elimesika earned 2000 total points
ID: 21876060
HI

I have made several modifications to make the code more readable and use .NET 3.5
using System;
using System.IO;
using System.ServiceProcess;
using System.Threading;
using System.Timers;
 
namespace myFileCopyService
{
    public class Service1 : ServiceBase
    {
        private readonly string[,] cam = new string[48,2];
 
        public Service1()
        {
            InitializeComponent();
        }
 
        protected override void OnStart(string[] args)
        {
            timer1.Enabled = true;
 
            cam.SetValue("CAM01", 0, 0);
            cam.SetValue("CS07", 0, 1);
            cam.SetValue("CAM02", 1, 0);
            cam.SetValue("CS07", 1, 1);
            cam.SetValue("CAM03", 2, 0);
            cam.SetValue("CS07", 2, 1);
            cam.SetValue("CAM04", 3, 0);
            cam.SetValue("CS07", 3, 1);
            cam.SetValue("CAM05", 4, 0);
            cam.SetValue("CS08", 4, 1);
            cam.SetValue("CAM06", 5, 0);
            cam.SetValue("CS08", 5, 1);
            cam.SetValue("CAM07", 6, 0);
            cam.SetValue("CS08", 6, 1);
            cam.SetValue("CAM08", 7, 0);
            cam.SetValue("CS08", 7, 1);
            cam.SetValue("CAM09", 8, 0);
            cam.SetValue("CS09", 8, 1);
            cam.SetValue("CAM10", 9, 0);
            cam.SetValue("CS09", 9, 1);
            cam.SetValue("CAM11", 10, 0);
            cam.SetValue("CS09", 10, 1);
            cam.SetValue("CAM12", 11, 0);
            cam.SetValue("CS09", 11, 1);
            cam.SetValue("CAM13", 12, 0);
            cam.SetValue("CS10", 12, 1);
            cam.SetValue("CAM14", 13, 0);
            cam.SetValue("CS10", 13, 1);
            cam.SetValue("CAM15", 14, 0);
            cam.SetValue("CS10", 14, 1);
            cam.SetValue("CAM16", 15, 0);
            cam.SetValue("CS10", 15, 1);
            cam.SetValue("CAM17", 16, 0);
            cam.SetValue("CS11", 16, 1);
            cam.SetValue("CAM18", 17, 0);
            cam.SetValue("CS11", 17, 1);
            cam.SetValue("CAM19", 18, 0);
            cam.SetValue("CS11", 18, 1);
            cam.SetValue("CAM20", 19, 0);
            cam.SetValue("CS11", 19, 1);
            cam.SetValue("CAM21", 20, 0);
            cam.SetValue("CS12", 20, 1);
            cam.SetValue("CAM22", 21, 0);
            cam.SetValue("CS12", 21, 1);
            cam.SetValue("CAM23", 22, 0);
            cam.SetValue("CS12", 22, 1);
            cam.SetValue("CAM24", 23, 0);
            cam.SetValue("CS12", 23, 1);
            cam.SetValue("CAM25", 24, 0);
            cam.SetValue("CS01", 24, 1);
            cam.SetValue("CAM26", 25, 0);
            cam.SetValue("CS01", 25, 1);
            cam.SetValue("CAM27", 26, 0);
            cam.SetValue("CS01", 26, 1);
            cam.SetValue("CAM28", 27, 0);
            cam.SetValue("CS01", 27, 1);
            cam.SetValue("CAM29", 28, 0);
            cam.SetValue("CS02", 28, 1);
            cam.SetValue("CAM30", 29, 0);
            cam.SetValue("CS02", 29, 1);
            cam.SetValue("CAM31", 30, 0);
            cam.SetValue("CS02", 30, 1);
            cam.SetValue("CAM32", 31, 0);
            cam.SetValue("CS02", 31, 1);
            cam.SetValue("CAM33", 32, 0);
            cam.SetValue("CS03", 32, 1);
            cam.SetValue("CAM34", 33, 0);
            cam.SetValue("CS03", 33, 1);
            cam.SetValue("CAM35", 34, 0);
            cam.SetValue("CS03", 34, 1);
            cam.SetValue("CAM36", 35, 0);
            cam.SetValue("CS03", 35, 1);
            cam.SetValue("CAM37", 36, 0);
            cam.SetValue("CS04", 36, 1);
            cam.SetValue("CAM38", 37, 0);
            cam.SetValue("CS04", 37, 1);
            cam.SetValue("CAM39", 38, 0);
            cam.SetValue("CS04", 38, 1);
            cam.SetValue("CAM40", 39, 0);
            cam.SetValue("CS04", 39, 1);
            cam.SetValue("CAM41", 40, 0);
            cam.SetValue("CS05", 40, 1);
            cam.SetValue("CAM42", 41, 0);
            cam.SetValue("CS05", 41, 1);
            cam.SetValue("CAM43", 42, 0);
            cam.SetValue("CS05", 42, 1);
            cam.SetValue("CAM44", 43, 0);
            cam.SetValue("CS05", 43, 1);
            cam.SetValue("CAM45", 44, 0);
            cam.SetValue("CS06", 44, 1);
            cam.SetValue("CAM46", 45, 0);
            cam.SetValue("CS06", 45, 1);
            cam.SetValue("CAM47", 46, 0);
            cam.SetValue("CS06", 46, 1);
            cam.SetValue("CAM48", 47, 0);
            cam.SetValue("CS06", 47, 1);
        }
 
        protected override void OnStop()
        {
            timer1.Enabled = false;
        }
 
        private void timer1_Elapsed(object sender, ElapsedEventArgs e)
        {
            DateTime systemDate = DateTime.Now;
            DateTime startDate = DateTime.Today.AddHours(6.5D);
            DateTime endDate = DateTime.Today.AddHours(18D);
            int d = Convert.ToInt32(Convert.ToString((int) DateTime.Now.DayOfWeek + 1));
            if ((systemDate >= startDate) && (systemDate <= endDate))
            {
                if ((d == 1) | (d == 7))
                {
                    return;
                }
            }
            else
            {
                return;
            }
 
            string dy = "0" + Convert.ToString((int) DateTime.Now.DayOfWeek + 1);
            string hr = Right("0" + Convert.ToString(DateTime.Now.Hour), 2);
            string mn = Right("0" + Convert.ToString(DateTime.Now.Minute), 2);
            string sc = Right("0" + Convert.ToString(DateTime.Now.Second), 2);
            string fn = @"\DY" + dy + @"\H" + hr + @"\H" + hr + "M" + mn + "S" + sc + ".jpg";
 
            try
            {
                var Paths = new string[48,2];
                for (int i = 0; i <= 47; i++)
                {
                    Paths[i, 0] = @"D:\Sec\CamFolder\LivePics\" + cam[i, 1] + "_" + cam[i, 0] + "_TEMP.jpg";
                    Paths[i, 1] = @"F:\CS\" + cam[i, 0] + fn;
                }
                var x01 = new FFC {pGF = Paths[1, 0], pST = Paths[1, 1]};
                var t01 = new Thread(x01.MethodFFC);
                t01.Start();
                var x02 = new FFC {pGF = Paths[2, 0], pST = Paths[2, 1]};
                var t02 = new Thread(x02.MethodFFC);
                t02.Start();
                var x03 = new FFC {pGF = Paths[3, 0], pST = Paths[3, 1]};
                var t03 = new Thread(x03.MethodFFC);
                t03.Start();
                var x04 = new FFC {pGF = Paths[4, 0], pST = Paths[4, 1]};
                var t04 = new Thread(x04.MethodFFC);
                t04.Start();
                var x05 = new FFC {pGF = Paths[5, 0], pST = Paths[5, 1]};
                var t05 = new Thread(x05.MethodFFC);
                t05.Start();
                var x06 = new FFC {pGF = Paths[6, 0], pST = Paths[6, 1]};
                var t06 = new Thread(x06.MethodFFC);
                t06.Start();
                var x07 = new FFC {pGF = Paths[7, 0], pST = Paths[7, 1]};
                var t07 = new Thread(x07.MethodFFC);
                t07.Start();
                var x08 = new FFC {pGF = Paths[8, 0], pST = Paths[8, 1]};
                var t08 = new Thread(x08.MethodFFC);
                t08.Start();
                var x09 = new FFC();
                x09.pGF = Paths[9, 0];
                x09.pST = Paths[9, 1];
                var t09 = new Thread(x09.MethodFFC);
                t09.Start();
                var x10 = new FFC();
                x10.pGF = Paths[10, 0];
                x10.pST = Paths[10, 1];
                var t10 = new Thread(x10.MethodFFC);
                t10.Start();
                var x11 = new FFC {pGF = Paths[11, 0], pST = Paths[11, 1]};
                var t11 = new Thread(x11.MethodFFC);
                t11.Start();
                var x12 = new FFC();
                x12.pGF = Paths[12, 0];
                x12.pST = Paths[12, 1];
                var t12 = new Thread(x12.MethodFFC);
                t12.Start();
                var x13 = new FFC();
                x13.pGF = Paths[13, 0];
                x13.pST = Paths[13, 1];
                var t13 = new Thread(x13.MethodFFC);
                t13.Start();
                var x14 = new FFC();
                x14.pGF = Paths[14, 0];
                x14.pST = Paths[14, 1];
                var t14 = new Thread(x14.MethodFFC);
                t14.Start();
                var x15 = new FFC();
                x15.pGF = Paths[15, 0];
                x15.pST = Paths[15, 1];
                var t15 = new Thread(x15.MethodFFC);
                t15.Start();
                var x16 = new FFC();
                x16.pGF = Paths[16, 0];
                x16.pST = Paths[16, 1];
                var t16 = new Thread(x16.MethodFFC);
                t16.Start();
                var x17 = new FFC();
                x17.pGF = Paths[17, 0];
                x17.pST = Paths[17, 1];
                var t17 = new Thread(x17.MethodFFC);
                t17.Start();
                var x18 = new FFC();
                x18.pGF = Paths[18, 0];
                x18.pST = Paths[18, 1];
                var t18 = new Thread(x18.MethodFFC);
                t18.Start();
                var x19 = new FFC();
                x19.pGF = Paths[19, 0];
                x19.pST = Paths[19, 1];
                var t19 = new Thread(x19.MethodFFC);
                t19.Start();
                var x20 = new FFC();
                x20.pGF = Paths[20, 0];
                x20.pST = Paths[20, 1];
                var t20 = new Thread(x20.MethodFFC);
                t20.Start();
                var x21 = new FFC();
                x21.pGF = Paths[21, 0];
                x21.pST = Paths[21, 1];
                var t21 = new Thread(x21.MethodFFC);
                t21.Start();
                var x22 = new FFC();
                x22.pGF = Paths[22, 0];
                x22.pST = Paths[22, 1];
                var t22 = new Thread(x22.MethodFFC);
                t22.Start();
                var x23 = new FFC();
                x23.pGF = Paths[23, 0];
                x23.pST = Paths[23, 1];
                var t23 = new Thread(x23.MethodFFC);
                t23.Start();
                var x24 = new FFC();
                x24.pGF = Paths[24, 0];
                x24.pST = Paths[24, 1];
                var t24 = new Thread(x24.MethodFFC);
                t24.Start();
                var x25 = new FFC();
                x25.pGF = Paths[25, 0];
                x25.pST = Paths[25, 1];
                var t25 = new Thread(x25.MethodFFC);
                t25.Start();
                var x26 = new FFC();
                x26.pGF = Paths[26, 0];
                x26.pST = Paths[26, 1];
                var t26 = new Thread(x26.MethodFFC);
                t26.Start();
                var x27 = new FFC();
                x27.pGF = Paths[27, 0];
                x27.pST = Paths[27, 1];
                var t27 = new Thread(x27.MethodFFC);
                t27.Start();
                var x28 = new FFC();
                x28.pGF = Paths[28, 0];
                x28.pST = Paths[28, 1];
                var t28 = new Thread(x28.MethodFFC);
                t28.Start();
                var x29 = new FFC();
                x29.pGF = Paths[29, 0];
                x29.pST = Paths[29, 1];
                var t29 = new Thread(x29.MethodFFC);
                t29.Start();
                var x30 = new FFC();
                x30.pGF = Paths[30, 0];
                x30.pST = Paths[30, 1];
                var t30 = new Thread(x30.MethodFFC);
                t30.Start();
                var x31 = new FFC();
                x31.pGF = Paths[31, 0];
                x31.pST = Paths[31, 1];
                var t31 = new Thread(x31.MethodFFC);
                t31.Start();
                var x32 = new FFC();
                x32.pGF = Paths[32, 0];
                x32.pST = Paths[32, 1];
                var t32 = new Thread(x32.MethodFFC);
                t32.Start();
                var x33 = new FFC();
                x33.pGF = Paths[33, 0];
                x33.pST = Paths[33, 1];
                var t33 = new Thread(x33.MethodFFC);
                t33.Start();
                var x34 = new FFC();
                x34.pGF = Paths[34, 0];
                x34.pST = Paths[34, 1];
                var t34 = new Thread(x34.MethodFFC);
                t34.Start();
                var x35 = new FFC();
                x35.pGF = Paths[35, 0];
                x35.pST = Paths[35, 1];
                var t35 = new Thread(x35.MethodFFC);
                t35.Start();
                var x36 = new FFC();
                x36.pGF = Paths[36, 0];
                x36.pST = Paths[36, 1];
                var t36 = new Thread(x36.MethodFFC);
                t36.Start();
                var x37 = new FFC();
                x37.pGF = Paths[37, 0];
                x37.pST = Paths[37, 1];
                var t37 = new Thread(x37.MethodFFC);
                t37.Start();
                var x38 = new FFC();
                x38.pGF = Paths[38, 0];
                x38.pST = Paths[38, 1];
                var t38 = new Thread(x38.MethodFFC);
                t38.Start();
                var x39 = new FFC();
                x39.pGF = Paths[39, 0];
                x39.pST = Paths[39, 1];
                var t39 = new Thread(x39.MethodFFC);
                t39.Start();
                var x40 = new FFC();
                x40.pGF = Paths[40, 0];
                x40.pST = Paths[40, 1];
                var t40 = new Thread(x40.MethodFFC);
                t40.Start();
                var x41 = new FFC();
                x41.pGF = Paths[41, 0];
                x41.pST = Paths[41, 1];
                var t41 = new Thread(x41.MethodFFC);
                t41.Start();
                var x42 = new FFC();
                x42.pGF = Paths[42, 0];
                x42.pST = Paths[42, 1];
                var t42 = new Thread(x42.MethodFFC);
                t42.Start();
                var x43 = new FFC();
                x43.pGF = Paths[43, 0];
                x43.pST = Paths[43, 1];
                var t43 = new Thread(x43.MethodFFC);
                t43.Start();
                var x44 = new FFC();
                x44.pGF = Paths[44, 0];
                x44.pST = Paths[44, 1];
                var t44 = new Thread(x44.MethodFFC);
                t44.Start();
                var x45 = new FFC();
                x45.pGF = Paths[45, 0];
                x45.pST = Paths[45, 1];
                var t45 = new Thread(x45.MethodFFC);
                t45.Start();
                var x46 = new FFC();
                x46.pGF = Paths[46, 0];
                x46.pST = Paths[46, 1];
                var t46 = new Thread(x46.MethodFFC);
                t46.Start();
                var x47 = new FFC();
                x47.pGF = Paths[47, 0];
                x47.pST = Paths[47, 1];
                var t47 = new Thread(x47.MethodFFC);
                t47.Start();
            }
 
            catch (Exception exc)
            {
                Console.WriteLine("Exception " + exc.Message);
            }
        }
 
        private static string Right(string s, int count)
        {
            string newString = String.Empty;
            if (s != null && count > 0)
            {
                int startIndex = s.Length - count;
                if (startIndex > 0)
                    newString = s.Substring(startIndex, count);
                else
                    newString = s;
            }
            return newString;
        }
    }
 
    public class FFC
    {
        public string pGF;
        public string pST;
 
        public void MethodFFC()
        {
            try
            {
                // Ensure that the target does not exist.
                File.Delete(pST);
 
                // Copy the file.
                File.Copy(pGF, pST);
                //Console.WriteLine("{0} copied to {1}", PathGetFrom, PathSaveTo);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
    }
}

Open in new window

0
 

Author Comment

by:ascnd
ID: 21877970
elimesika,

Thanks for your help.  One last thing, can this be simplified more?

int d = Convert.ToInt32(Convert.ToString((int) DateTime.Now.DayOfWeek + 1));
0
 
LVL 19

Expert Comment

by:elimesika
ID: 21881111
yes
int d;
Int32.TryParse((DateTime.Now.DayOfWeek + 1).ToString(), out d);

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question