Skip to main content
1 vote
3 answers
147 views

Why are Minimal API endpoints waiting for Tasks?

Building a basic ASP.NET Core Minimal API, I was surprised by the fact that if an endpoint returns a Task, the request does not return until the Task is done: var builder = WebApplication....
Pragmateek's user avatar
  • 13.5k
1 vote
2 answers
97 views

Why do `ParallelQuery.ToArray()` and `ToList()` return ordered sequence?

The doc listed the operators in the table that ToArray should be unordered when the parallelquery source is unordered. However, the result turned out to be always ordered when force evaluated to array ...
jamgoo's user avatar
  • 107
0 votes
2 answers
98 views

Any side effects when writing LINQ-like extensions for Task<IEnumerable<T>>?

I'm a little bit annoyed of parentheses in situations like this: var items = (await SomeService.GetDataAsEnumerableAsync()).ToList(); So I thought of creating an extension method like: public static ...
David Ritter's user avatar
1 vote
2 answers
65 views

Task.WaitAll does not throw as expected

I was expecting Task.WaitAll to throw when semaphore reaches its maxcount, but the result is, all tasks were hanged. SemaphoreSlim semaphore = new(initialCount: 3, maxCount: 10); var tasks = ...
jamgoo's user avatar
  • 107
2 votes
2 answers
87 views

Executing mixed tasks in parallel

I have ~10000 objects of type System.Text.Json.JsonDocument. For each JsonDocument in parallel, I have to do the following steps in order. clone JsonDocument to JsonNode apply a sequence of tasks ...
lightning_missile's user avatar
0 votes
1 answer
89 views

Why does Task.Factory.StartNew for an async lambda work, when calling the lambda directly does not?

I'm writing a console application that needs to copy console input one keypress at a time to a socket (while also doing other things). In order to do that, I figure I have a couple options. In the ...
Mark's user avatar
  • 11.8k
0 votes
2 answers
82 views

Task.WhenAny with Task.Delay to implement a timeout mechanism does not work reliable

From within my ASP.NET application (.NET Framework 4.8) I invoke an external process via Anonymous Pipes. Theoretically, it could happen that the external process hangs (for whatever reason) when my ...
Jan Köhler's user avatar
  • 6,062
2 votes
1 answer
160 views

Passing CancellationTokenSource to awaited Task

Read a lot of articles an watch many videos on Task Cancelation. But I still can't quite follow if it's possible to pass CancellationTokenSource instead of CancellationTokenSource providing that the ...
Roman Ieromenko's user avatar
1 vote
1 answer
70 views

Why can't I catch AbandonedMutexException after a task

I was expecting to trigger a AbandonedMutexException after a task that does not release the mutex, the program stuck when WaitOne after the task: Mutex mutex = new(); BankAccount account = new(); ...
jamgoo's user avatar
  • 107
0 votes
0 answers
42 views

Deadlock issue when scheduling task computations (F#, .NET TPL)

I am in the process of building an effect system DSL with F# inspired by ZIO and Cats Effect. I have my effect type defined as a DU of opcodes, a fiber type, a channel type for message passing, etc. I ...
iyyel's user avatar
  • 55
2 votes
1 answer
77 views

Why does direct throwing OperationCanceledException cancels the task [duplicate]

I read the documentation says to set status to Canceled requires three conditions: OperationCanceledException(or its derived exception type such as TaskCanceledException) is thrown token....
jamgoo's user avatar
  • 107
1 vote
2 answers
117 views

AggregateException is not caught

I have a problem with AggregateException thrown from .NET library. For some reason it is not caught in try-catch block. It causes whole application to crash and there are no methods from my code in ...
Maciejosas's user avatar
1 vote
2 answers
90 views

How to implement a custom Task.WhenAll that preserves the order of exceptions?

The behavior of the non-generic Task.WhenAll changed in .NET 8, and now the order of the exceptions is in chronological order instead of positional order. The new behavior is not without merits, but I ...
Theodor Zoulias's user avatar
0 votes
0 answers
85 views

Where is the difference between await Task Event and Event.Wait

I have a communications driver. It was failing a few thousand times a day. But after changing a single line, it now works perfectly. // The event is set after 100ms at the latest ManualResetEvent ...
jeb's user avatar
  • 82.6k
0 votes
2 answers
129 views

Task issue with Powershell and TaskScheduler

I am writing a C# library (.NET 4.6.1) that will use Tasks to be able to run several snippets of code in the background. This library will be called by a Powershell script that is triggered from a ...
maegus's user avatar
  • 59

15 30 50 per page
1
2 3 4 5
420