Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String SampleProperty{
- get;
- private set;
- }
- private string sampleField;
- private object threadSafer = new object();
- public String SampleProperty{
- get{ return this.sampleField; }
- private set{
- lock(threadSafer){
- sampleField = value;
- }
- }
- }
- class BackgroundTaskDemo
- {
- private bool stopping = false;
- static void Main()
- {
- BackgroundTaskDemo demo = new BackgroundTaskDemo();
- new Thread(demo.DoWork).Start();
- Thread.Sleep(5000);
- demo.stopping = true;
- }
- static void DoWork()
- {
- while (!stopping)
- {
- // Do something here
- }
- }
- }
- lock(someExternalLock) {
- record.Foo = "Bar";
- }
- lock(record.SyncLock) {
- record.Foo = "Bar";
- }
- obj.SampleProperty = "Dear " + firstName + " " + lastName;
- obj.SampleProperty += obj.SampleProperty + "a";
- obj.SampleProperty = "Initial String Value";
Add Comment
Please, Sign In to add comment