How does static code run with multiple threads?

后端 未结 6 861
青春惊慌失措
青春惊慌失措 2021-01-04 06:38

I was reading Threading from within a class with static and non-static methods and I am in a similar situation.

I have a static method that pulls data from a resourc

6条回答
  •  时光说笑
    2021-01-04 07:13

    If the static method is written to be thread safe, then it can be called from any thread or even passed to a thread pool.

    You have to keep in mind - .NET objects don't live on threads (with the exception of structs located on a thread's stack) - paths of execution do. So, if a thread can access an instance of an object it can call an instance method. Any thread can call a static method because it all needs to know about is the type of the object.

提交回复
热议问题