Reputation: 4878
I have a singleton static class that contains settings, Settings.Instance.MemberName
.
This class is in GlobalSettings project inside a solution that contains several projects.
All projects are compiled as DLL and used by an external Windows Service process.
In one project in this solution, I have 100-200 instances of ClassA
, this class is used for polling data from device using a Network Socket.
The polling is done with certain logic, And I use settings from Settings.Instance
,
e.g for settings is sleep time between polling.
socket.Send(..);
Thread.Sleep(Settings.Instance.SleepBetweenSendAndReceive);
socket.Receive(..);
My question is, What is better to do ?
All instance should call Settings.Instance.MaxNetworkRetries directly as above.
In ClassA constructor, I should load all settings to a local static private members
(Thread.Sleep(_sleepBetweenSendAndReceive);)
In ClassA constructor, I should load all settings to a local private members
(Thread.Sleep(_sleepBetweenSendAndReceive);)
What would give best performance? Or maybe there is no difference at all.
Upvotes: 1
Views: 120
Reputation: 26436
I can't imagine there are any performance issues there if all you want to do is Sleep()
anyway.
When network communication is involved, the network usually is the bottleneck, and the overhead of a property call is neglectable.
If you want to increase performance in your application, you could remove the Sleep()
, and either block on Receive()
or receive data asynchronously (if you're not sure you're going to receive data).
But in the end, accessing a field in the same class should be faster than a property of a property of a static class. You could write a sample project without network communication, and time the difference.
Upvotes: 2