Link to home
Start Free TrialLog in
Avatar of center1010
center1010

asked on

c# Task with arguments

like this it's working:

        public static OrderRS Method1()
        {

            OrderRS result = new OrderRS();

            return result;

        }

        static void BS()
        {

            Task<OrderRS> TheFirst = Task.Factory.StartNew<OrderRS>(Method1);

            Task TheSecond =TheFirst.ContinueWith(x=>
                {
                    OrderRS t = x.Result;
                    int r = t.OrderId;
                });
           
        }

Open in new window


But i need  to add arguments to Method1 like this:
        public static OrderRS Method1(int r1,Trs r2)
        {

            OrderRS result = new OrderRS();

            return result;

        }

        static void BS()
        {

            Task<OrderRS> TheFirst = Task.Factory.StartNew<OrderRS>(Method1(r1,Trs));

            Task TheSecond =TheFirst.ContinueWith(x=>
                {
                    OrderRS t = x.Result;
                    int r = t.OrderId;
                });

           
        }

Open in new window


How can i do it?
and how can i use the result from the second task?
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Where is the type Trs defined, most likely the cause of the issue. Please post the error message you are getting.

public static OrderRS Method1(int r1,Trs r2)
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial