I have a function in C# that can be called multiple times from multiple threads and I want it to be done only once so I thought about this:
class MyClass {
The lock keyword is just syntactic sugar for the Monitor class. Also you could call Monitor.Enter(), Monitor.Exit().
lock
But the Monitor class itself has also the functions TryEnter() and Wait() which could help in your situation.