public bool IsFinished()
    {
        if (converters == null || converters.Count != numThreadsPerImage)
        {
            return(false);
        }

        for (int i = 0; i < converters.Count; i++)
        {
            ImagePieceToColorArray converter = converters[i];

            if (!converter.finished)
            {
                return(false);
            }
        }

        if (!finished)
        {
            CombinePieces();
        }

        return(finished);
    }
    public void Convert()
    {
        Profiler.BeginThreadProfiling("ImageToColorArray", this.GetHashCode().ToString());
        try
        {
            Debug.Log("Starting conversion of entire file on thread " + Thread.CurrentThread.ManagedThreadId);
            converters = new List <ImagePieceToColorArray>();

            int picHeight = bitmap.Height;

            for (int i = 0; i < numThreadsPerImage; i++)
            {
                int start = i * (picHeight / numThreadsPerImage);
                int end   = (i + 1) * (picHeight / numThreadsPerImage);

                if (i == numThreadsPerImage - 1)
                {
                    end = picHeight;
                }

                Debug.LogFormat("Creating thread #{0} with start at {1} and end at {2}", i, start, end);

                Bitmap newBitmap = new Bitmap(bitmap);

                ImagePieceToColorArray newConverter = new ImagePieceToColorArray(newBitmap, start, end);
                converters.Add(newConverter);

                ThreadPool.QueueUserWorkItem(new WaitCallback(state => newConverter.Convert()));
            }
        }
        catch (Exception e)
        {
            Debug.LogErrorFormat("Exception on thread {0}: {1}", Thread.CurrentThread.ManagedThreadId, e);
        }
        Profiler.EndThreadProfiling();
    }