I'm writing a special data structure that will be available in a .NET library and one of the features of this data structure is that is will be thread safe provided that only one thread writes data to it, and only one thread reads data from it (the reader thread and the writer thread can be different).
The question is how can I enforce that all Read operations are executed by the same thread?
My solution would be capture the System.Threading.Thread.ManagedThreadID and store it in a private member upon the first Read. Then, on subsequent reads to check the ManagedThreadID against the saved one and if they are different to throw an exception.
Is that enough, or is there a different more reliable mechanism for doing this.
Note: There is a requirement that this library be usable without a Windows.Forms context..