KennanChan / Revit.Async

Use task-based asynchronous pattern (TAP) to run Revit API code from any execution context.
MIT License
223 stars 51 forks source link

Can't schedule more than 1 task in a synchronous method #9

Closed twastvedt closed 2 years ago

twastvedt commented 3 years ago

I have found that if I call RevitTask.RunAsync more than once before releasing control of the current thread (through async/await or ending the method), only the first task is ever run. Subsequent calls to RunAsync appear to work through the queue, calling the next method, but always behind. Most of the time this isn't an issue as I await calls to RunAsync. Occasionally, though, I have wanted to set several tasks to run but don't care about when they finish. It's not terribly hard to work around, but because it's not typically an issue with other asynchronous methods, it took me a while to find the issue. Is this intended, unavoidable, or fixable?

In summary, this works:

await RevitTask.RunAsync([something 1]);
await RevitTask.RunAsync([something 2]);

but this doesn't

// These are run from, say, a button press. Only [something 1] is executed.
  RevitTask.RunAsync([something 1]);
  RevitTask.RunAsync([something 2]);

// After the button press method is finished, this is run by another button.
  await RevitTask.RunAsync([something 3]); // This causes [something 2] to run
KennanChan commented 3 years ago

Thanks for the feedback and sorry for the late reply. It sounds like a design error, I'll take a look at this issue

KennanChan commented 3 years ago

@twastvedt Hi my friend. Thanks for the feedback and I have made some significant changes to this project these days. I tested myself and it works fine. Here is the PR #10 and I would like to ask you for help to run some more tests before it finally gets merged to master. Feel free to give me further feedbacks.

twastvedt commented 3 years ago

@KennanChan Sorry for the delay. Thanks for looking into this! I need to get a project out, but then I will absolutely test the update over here.

twastvedt commented 3 years ago

@KennanChan I gave it a whirl! Posted a couple comments on the PR, but just with the debug side. Everything looked to be working well! Thanks again!