Hi,

I have a question about the threadpool. ThreadPool accepts to pass along an object as shown in my code.

I will pass along 3 doubles, which I ofcourse could make to a string object, - and then convert it back to doubles in the "receiveDoubles" function. This is no problem to do.

However, I wonder if it is possible to pass along the doubles as type "double" and receive those 3 doubles as type "double" in the "receiveDoubles" function, which mean that no conversion will be needed anywhere?
(Reason is otherwise a huge amount of conversions)

        public void receiveDoubles(object getdoubles)
        {
            //Is it possible to receive doubles without converting here, which takes time?
            double one = 0;
            double two = 0;
            double three = 0;
        }
        private void button1_Click(object sender, EventArgs e)
        {

            object senddoubles = new object();

            //Send along those doubles
            double one = 21.51;
            double two = 21.52;
            double three = 21.53;

            ThreadPool.QueueUserWorkItem(new WaitCallback(receiveDoubles), senddoubles);
        }

Yes, create a structure to hold your doubles;

public struct MyDoubles {
    public double one;
    public double two;
    public double three;

    publid MyDoubles(double o, double t, double h) {
        one = o;
        two = t;
        three = h;
    }
}

Then you'd call your method

MyDoubles senddoubles = new MyDoubles(one, two, three);

ThreadPool.QueueUserWorkItem(new WaitCallback(receiveDoubles), senddoubles);

And in your receiveDoubles you'd convert it back to the structure

 public void receiveDoubles(object getdoubles) {
     MyDoubles sentDoubles = (MyDoubles) getdoubles;

     ...

Thanks Momerath,

That seems to be a good solution!

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.