Click here to Skip to main content
15,888,025 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to make a static method of a static class can be make multithreading ?
Posted

Yes - provided the threads don't need to share the same data simultaneously it is possible. You may need to look at the lock statment[^] though.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Apr-14 21:54pm    
Well, this is not the only case when, formally, using static properties and fields is possible with thread. Practically, it's a very bad thing. It is not really needed even with thread-shared data and should be best avoided.
—SA
Quite possible. Of course it's quite possible. Not only you can use multiple exclusion (lock statements, and the like), you also can use some static members (essentially, properties and fields, as static methods are widely used and don't present problem if they work only on stack).

But this is a very, vary bad idea. Using stack is the way to isolate threads. Static fields and properties are not needed even if you want to share data between threads. Please see my past answer:
Change parameters of thread (producer) after it is started[^],
Making Code Thread Safe[^],
Running exactly one job/thread/process in webservice that will never get terminated (asp.net)[^].

The main idea is: you need to synchronize threads only if they really need to communicate via some shared data or conveyors of data. In other cases, best synchronization is no synchronization. And this comes automatically if you isolate thread data and use more of the stack.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900