TIMOB-13665 Allow for code to happen during context launch. 3.1.1 backport

Backport of PR #4282