Was browsing through a project of mine and stumbled across the following code (and class) inside of a file MyWebExtentions which I have never seen before.
Private s_Computer As New ThreadSafeObjectProvider(Of Global.Microsoft.Vis开发者_Python百科ualBasic.Devices.ServerComputer)
''' <summary>
''' Returns information about the host computer.
''' </summary>
<Global.System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")> _
Friend ReadOnly Property Computer() As Global.Microsoft.VisualBasic.Devices.ServerComputer
Get
Return s_Computer.GetInstance()
End Get
End Property
So I tried looking at the object explorer and it doesnt appear, searching MSDN and nothing, tried stackoverflow also nothing. In the end I did find this article which does explain that it allows you to create a "thread safe, thread specific storage" but doesn't explain, why or how.
So could someone please be kind enough to explain what is the purpose of this class, how it works and if there any appropriate usage scenarios for this class in non designer generated code?
For when you want a particular variable to be thread static but need to create a thread static variable for each context that calls your method. You would use this. This keeps thread static variables per context where declaring something as thread static would keep it only for the thread on which it was created.
That's my understanding which honestly might be completely bogus but is how i interpreted it and acts as an example of why I gave on working in WCF for a while.
Seriously though, downvote this if you must but this is my best attempt to answer.
精彩评论