Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I am developing multi thread application. in my application i am using one class for processing some of the calculation. For each device i am creating one separate instance of that class in thread.
The performance is very imp part of my development. if i use private static method for some of the calculation then i can increase some performance . what will be the impact if multiple threads are running. if there are multiple instance of the class what will be the scope of those private static methods ?
Dose the scope remains only for that instance of the class ? can anyone encounter or developed such kind of code.

Thanks for your help
Preetam Ramdhave
Posted

If you are creating instance of the class then you should avoid using static members, but if you are passing parameters in static method and not using any local variables from the class then it will not create any issue of cross thread.

Below link might help you more in detail
http://stackoverflow.com/questions/1992475/how-to-write-correct-static-methods-multithread-safe[^]

http://stackoverflow.com/questions/1090650/are-static-methods-thread-safe[^]

http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/c3cc953f-4659-44b2-8107-3e25d23fb02a/[^]
 
Share this answer
 
Comments
Preetam U Ramdhave 2-Apr-13 6:00am    
Hi Vijay,
Thanks for your comments.
let me give you more clear view. if you have one task. to complite this task you break this taks in smaller task. you have created non static class for the task. now you are developing the methods for the task which are break up in smaler parts.
if i use those task as a private method. so the scope of those static method will be limited for that instance only isn't it ?
so using that private static method without exposing any public property which is static. is it thread same ?
Hi,
I have done some reading and was not able to find any thing. so i wrote one program to check that

C#
class Test
  {
       int privVariable =10;
      public void GetInfo(int i)
      {
          privVariable = SetInformation(i);
      }
      private static int SetInformation(int SendValue)
      {
          return SendValue = SendValue * 22;
      }
  }


this code works fine.
but in case if you write private static method then it will be accable for all the class instance of that class
so the answer is no you shoud carefully use static method in your multi thread application

Regards
Preetam Ramdhave
 
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