Is there a situation where a SynchronisationContext is used over multiple threads/tasks in Blazor?
I want to determine whether a method has an components BuildRenderTree in its call stack. To do so i created a custom ComponentBase where i wrap the BuildRenderTree with custom code. My approach would be to check the SynchronisationContext. As i understood it is uniquely for one component, and therefor the execution of BuildRenderTree will not be "interrupted" by other threads/tasks with the same SynchronisationContext set. Did i get this right? Are there any pitfalls with using the SynchronisationContext for this case? (i am not sure if the components used in the razor file are rendered within the BuildRenderTree but i would handle this case correctly alreay)
As i understood it is uniquely for one component,
Not really. It is attached to the SignalR circuit and shared by the whole UI. It is null when running on WebAssembly.
and therefor the execution of BuildRenderTree will not be "interrupted" by other threads/tasks with the same SynchronisationContext set.
BuildRenderTree() is not async, it won't be interrupted by other Tasks. It might be pre-empted by other threads but that should not affect what's on the call stack.