none
How to implement custom class which has the same function as System.Threading.Tasks.Task.ContinueWith(task=>Action)? RRS feed

  • Question

  • How to implement custom class which has the same function as System.Threading.Tasks.Task.ContinueWith(task=>Action)?
    Monday, December 31, 2012 1:42 AM

All replies

  • Can you explain the result you can to achieve with it?
    Monday, December 31, 2012 8:06 AM
  • Hi Xqcdd,

    This doesn't make sense. Why do you need to implement is again? What kind of things it doesn't implement?

    Have a nice day.


    Ghost,
    Call me ghost for short, Thanks
    To get the better answer, it should be a better question.

    Tuesday, January 1, 2013 6:12 AM
  • The only sens I understand to suggestion isn't directly multithreading related but related to the possibility to chain exécutions.

    If I imagine you have an Executable class with a Run() method and a Code delegate executed by the Run() method (the Code member can also be some other kind of delegate, virtual method, event, Func<...>, Action<...>, or even an expression tree...) .  You may want to chain Executable instances and the Run() method to be able to execute the self instance Code and then to launch the Run method of ContinueWith() attached Executable instance ?

    The Executable class may have a list of _continueWithExecutuables and the Run() method will looks like

    public void Run()

    {

      Code();

      foreach(var continueWith in _continueWithExecutables)
        continueWith.Run();

    }

    the ContinueWith implementation can be :

    public void ContinueWith(Action action)

    {

      _continueWithExecutables.Add(new Executable(action));

    }

    public void ContinueWith(Executable executable)

    {

      _continueWithExecutables.Add(executable);

    }

    You have to understand that if you want to make this compatible with all Func<...> and Action<....> and even Task<....> you will have to write many implémentations of the ContinueWith() method.

    I'm not certain that this reply to your question but it may help you to be more precise.

    Thursday, February 14, 2013 1:48 AM