I need to make a API call, but I want to wrap the call in a (C#) lock.
What options do I have to wrap some logic in a lock to make it thread safe?
Is it possible to mark a particular class or method as serializable also?
blah blah blah is here! blah blah » Close
1 answers
This is a typical pattern for locking some 'critical code' in C# so that it can only be accessed by one thread at a time.
You can make the class binary serializable by decorating it with the [Serializable] attribute. However, it wouldn't make sense to apply this attribute to methods as it's the class's fields which are serializable, not local variables.
answered 2 years ago by:
17279