c# - Locking properties vs Locking the entire object. Which is better for performance? -




i writing triggerbot , i'm creating class called settings contain private variables (all controls in form) , public properties (bools , ints)

public class settings {     private bunifucustomtextbox xoffsettb;     private bunifucustomtextbox yoffsettb;     private bunifucustomtextbox scanintervaltb;     private bunifucustomtextbox rclickintervaltb;     private bunifucustomtextbox snipewatitimetb;     private bunifucustomtextbox arrowwaittimetb;     private bunifucheckbox closerangerclickcb;     private bunifucheckbox longrangerclickcb;     private bunifucheckbox closerangelclickcb;     private bunifucheckbox longrangelclickcb;     private bunifuswitch kinessamodecb;     private bunifuswitch shalinmodecb;     private bunifuiosswitch drawcb;     private bunifuiosswitch disableonshiftcb;      public int xoffset { get; set; }     public int yoffset { get; set; }     public int scaninterval { get; set; }     public int rclickinterval { get; set; }     public int snipewaittime { get; set; }     public int arrowwaittime { get; set; }     public bool closerangerclick { get; set; }     public bool longrangerclick { get; set; }     public bool closerangelclick { get; set; }     public bool kinessamode { get; set; }     public bool shalinmode { get; set; }     public bool draw { get; set; }     public bool disableonshift { get; set; }  } 

i'll writing set statements value controls , set values controls.

i want program update on fly user changes input there should lock either entire settings class or each individual property in settings class. better choice in terms of performance ?

note know i'll have invoke main thread change values in controls. know thread using these properties should creates it's own private copy of variables , release lock before trying else. main concern performance , if lock settings class within infinite loop no thread.sleep(xx); there possibility that, thread have settings variable locked ? cause similar happened while experimenting on project

performance-wise i'm pretty sure same performance. when use lock(object), using reference number create exclusion zone, , other lock on same object require first complete. achieving approach, avoid collisions between user updating different field. also, possible benefits concurrency can added overhead of having multiple exclusion zones. small experiment, timing both approachs.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -