Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have an application written in C# that have static methods.

Question: If I run two instances of the executable, running at the same time, is there a clash between the two applications simply because they have static methods?

Reason I'm asking is that someone told me this might happen.
Posted
Comments
Vedat Ozan Oner 10-Feb-14 15:52pm    
no
radnix 10-Feb-14 17:39pm    
To the point, Thank you :)

1 solution

No, never. The processes are well isolated; each process runs in a separate isolated address space. On advanced processor architectures usually used for Windows systems (x86, x86-64, IE-64), this is the hardware protection at the level of CPU. If the processes are of the same application, it does not matter.

Besides, any possible clashes (inside the same process) can really happen and are associated with static fields or properties, in other words, with something where you share the same memory location. It has nothing to do with static methods. You simply don't quite understand what are they. They are just similar to "usual" non-OOP functions/procedures, in contrast to instance methods. In instance method gets an implicit "this" pointer (reference, managed pointer, in case of CLI), which references some instance of your type, so you can access other instance members of the instance. A static method does not get this reference and cannot access any instance. That's it.

Please see my past answers on static methods vs. instance methods:
Type casting in c#[^],
C# windows base this key word related and its uses in the application[^],
What makes static methods accessible?[^].

—SA
 
Share this answer
 
v2
Comments
ZurdoDev 10-Feb-14 16:23pm    
My +5. A simple No would have sufficed. :)
Sergey Alexandrovich Kryukov 10-Feb-14 17:38pm    
Thank you, Ryan.
You see, a developer needs to understand the background on all of the code one writes...
—SA
radnix 11-Feb-14 8:57am    
Thank you, Sergey
BillWoodruff 10-Feb-14 23:27pm    
+5 Very useful explanation !
Sergey Alexandrovich Kryukov 11-Feb-14 0:17am    
Thank you, Bill.
—SA

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