avo
avo

Reputation: 10711

Win32 QueueUserAPC API alternative in .NET

What would be the closest .NET alternative for QueueUserAPC? Should I use SynchronizationContext.Post for that?

Upvotes: 2

Views: 264

Answers (1)

Adrian Petrescu
Adrian Petrescu

Reputation: 493

Modern .NET tries to abstract away raw threading, and to replace with higher level libraries such as Task Parallel Library (TPL) or Reactive Extensions.

I am not sure that in .NET there is an "alertable" state for a thread, like you can obtain with SleepEx, but you can always use TPL to queue a work item on the process thread pool.

Task.Start( () => { /* do work * });

This works particularly well if you're doing some sort of asynchronous IO operation in there, which will allow the same thread to be reused for running another queued task, while your original task is doing an asynchronous operation.

Upvotes: 1

Related Questions