Table of Contents

Method CheckAccess

Namespace
SodaFlow.Bindable.ObjectModel
Assembly
SodaFlow.Core.Bindable.ObjectModel.dll

CheckAccess()

Whether the calling thread is the one this scheduler posts to.

public bool CheckAccess()

Returns

bool

Remarks

There are two methods to answer yes, and the two tests must fail before this method answers no. A dispatcher usually supplies the same context instance on its own thread, but not in each condition. A nested message loop, or a copy that carries a priority, can supply a different one. Thus, the thread that SodaFlow captures with the context is the second answer. An answer of yes when the method is not sure is the contract. See CheckAccess().

This method compares the thread first, and that sequence is necessary. A read of Current is not a cheap thread-local read. On .NET Framework it goes through the execution context. This test measures 13.0ns when it reads the context first, and 3.1ns when it reads the thread identifier first. That is most of the cost of a checked read of a bindable value on that platform, which is 18.3ns against 6.4ns. The same change on .NET 8 is 2.3ns against 1.3ns. Thus, the older runtime, which these libraries support, is the cause of this sequence.

The cheap test first usually gives the answer yes before the method does the expensive test. That leaves the expensive test for the condition it covers: a dispatcher that moved its work to a different thread. BindableValueBenchmarks in SodaFlow.Benchmarks supplies these numbers, and it runs on the two runtimes for this cause.