Skip to content

How to control on which thread an asynchronous function is run? #509

Discussion options

You must be logged in to vote

Hello @handerss-tibco,

Is there a way to control which threads are used for executing the script?

Your question really has to do with .NET task continuation handling. In principle, yes, .NET gives you control over how task continuation work items are queued and processed.

If you wish to route task continuation to a given thread, you need two things:

  1. A way to post work items to the target thread, which must be running an event loop of some kind.
  2. A SynchronizationContext that posts task continuation callbacks to your work queue.

.NET's Windows Desktop SDK includes the Dispatcher class, which neatly satisfies both requirements (see example below). On other platforms you'll have to implem…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@handerss-spotfire
Comment options

Answer selected by handerss-spotfire
Comment options

You must be logged in to vote
3 replies
@ClearScriptLib
Comment options

@handerss-spotfire
Comment options

@ClearScriptLib
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants