c# 4 task with arguments return object and continuewith the arguments from first

Please I need the syntax to :

1.  Start new task on a form (the task gest 3 or more arguments and return an object )
2.  One property of the result object is passed to textbox

3.  And other property of the result object is the input to continuewith to the first task

4.  The app must continue run and not wait for the task to end

EXTRA: is there a way to do it in c#5 with await/sync
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
A BackgroundWorker will do 1 and 4.

Requirement 2 is pretty much
txtbox.Text = ob.MyText;

Requirement 3 doesn't make sense.  You want the result of the task to be one of its starting arguments (isn't that a time machine you require)
center1010Author Commented:
Thank you for your answer, but i was more on this way

using System;
using System.Threading;
using System.Threading.Tasks;

class ContinuationSimpleDemo

        Action<string> action =
            (str) =>
                Console.WriteLine("Task={0}, str={1}, Thread={2}", Task.CurrentId, str, Thread.CurrentThread.ManagedThreadId);

Func<int, int> negate =
            (n) =>
                Console.WriteLine("Task={0}, n={1}, -n={2}, Thread={3}", Task.CurrentId, n, -n, Thread.CurrentThread.ManagedThreadId);
                return -n;

          // Creating a sequence of tasks where you can mix and match the types
        Console.WriteLine("\nCreating a sequence of tasks where you can mix and match the types");
        Task<int>.Factory.StartNew(() => negate(6))
            .ContinueWith(antecendent => action("x"))
            .ContinueWith(antecendent => negate(7))


Open in new window

1.  can i  get the value before the first  "ContinueWith" and use it in the form(even if  the "ContinueWith" method is still running?)
2.  i didn't understand what is " Func<int,int>negate =  (n)"
way not  " Func<int>negate =  (n) " like generics?
3. how can i use Object types instad of  int?
Create a class with properties for your arguments. Lets say Arguments class.

TaskFactory.StartNew<TResult>( (arguments) => {

//do what you have to

return result;

}).ContinueWith( task =>
    var result = task.Result;

//Use UI dispatcher to set the textbox value to from result
// do other steps


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.