Git Product home page Git Product logo

Comments (4)

philliphoff avatar philliphoff commented on August 28, 2024

@stuartleeks Do you have a repro project that you can share? I threw together a project but do not see that behavior; the workflow completes as expected once all the activities complete, whether .ToList() is used or not.

from dotnet-sdk.

stuartleeks avatar stuartleeks commented on August 28, 2024

@philliphoff - I've created a stripped back version of the project where I hit this and pushed it here: https://github.com/stuartleeks/dapr-wf-csharp-1211

Hopefully it's easy to set up/run, but let me kjnow if you have any questions

from dotnet-sdk.

philliphoff avatar philliphoff commented on August 28, 2024

Ok, so found the problem:

	await Task.WhenAll(activityTasks);

	var result = activityTasks.Select(t=>t.Result).ToArray();

...should instead be:

	var result = await Task.WhenAll(activityTasks);

In the original, activityTasks is a LINQ-based lazily-evaluated IEnumerable<Task>. It will first be evaluated by the Task.WhenAll() which causes the activities to be spawned and then awaited. Once that's done, it gets to the activityTasks.Select(t=>t.Result).ToArray(). This causes a second evaluation of the enumerable which spawns the activities again, but then tries to synchronously wait for each to finish (due to the use of Result), which is where I think the problem arises.

Task.WhenAll() returns the results of each awaited Task so that they can be used without reevaluating the original enumerable.

from dotnet-sdk.

stuartleeks avatar stuartleeks commented on August 28, 2024

Ah, good spot 🤦

Thanks!

from dotnet-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.