0

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);
        }
2
Contributors
2
Replies
11
Views
4 Years
Discussion Span
Last Post by Franze
0

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;

     ...
0

Thanks Momerath,

That seems to be a good solution!

Regards

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.