How to detect cross thread access in .NET (enforce thread affinity)?

后端 未结 3 1970
耶瑟儿~
耶瑟儿~ 2021-02-06 09:20

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 o

3条回答
  •  感动是毒
    2021-02-06 09:30

    Could you not require the Read and Write methods take a thread or thread ID? Then you can just compare against the one that called it first, and if it doesn't match, throw an exception or return an error code, or ignore the request.

    Otherwise, what you propose should work also. You need only compare the thread IDs.

提交回复
热议问题