V
V
vladimirchelyabinskiy2016-08-02 09:33:46
C++ / C#
vladimirchelyabinskiy, 2016-08-02 09:33:46

How to simplify (optimize) the code?

Good afternoon.
There is a code:

static void Main(string[] args)
        {
            Thread ThreadData1 = new Thread(new ThreadStart(fData1));
            ThreadData1.IsBackground = true;
            ThreadData1.Start();

            Thread ThreadData2 = new Thread(new ThreadStart(fData2));
            ThreadData2.IsBackground = true;
            ThreadData2.Start();

            Thread ThreadData3 = new Thread(new ThreadStart(fData3));
            ThreadData3.IsBackground = true;
            ThreadData3.Start();

            ThreadData1.Join();
            ThreadData2.Join();
            ThreadData3.Join();
        }

        public static void fData1()
        {
            foreach (string l in Data1)
                OptimizeIStage1(l, dataA);
        }

        public static void fData2()
        {
            foreach (string l in Data2)
                OptimizeIStage2(l, dataB);
        }

        public static void fData3()
        {
            foreach (string l in Data3)
                OptimizeIStage3(l, dataC);
        }

The program optimizes images, I will not go into details how.
There are 3 stages of optimization distributed over 3 threads
. How can I optimize the code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
akass, 2016-08-02
@vladimirchelyabinskiy

No need to work with Thread , take Task and everything will be much better

D
Daniil Demidko, 2016-08-03
@Daniro_San

Get rid of copypasta first

private Thread GetThreadData(ThreadStart startData)
{
    Thread result = new Thread(startData);
    result.IsBackground = true;
    result.Start();
    return result;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question