Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

duplication of a variable when running two threads c#

I have a global variable "mc" which has a value of 100 after the operation. if you run the method in a stream, then everything is fine, but if you run 2 streams, the value of "mc" will become 200. how to fix it?

if (mc.Count > 1) 
{ 
System.Threading.Thread MyThread1 = 
new System.Threading.Thread(delegate () { select_page(0, mc.Count / 2, 0); }); 
MyThread1.Start(); 
} 
else 
{ 
potoc1 = true; 
} 
 
System.Threading.Thread MyThread2 = 
new System.Threading.Thread(delegate () { select_page(mc.Count / 2, mc.Count, 1); }); 
MyThread2.Start();

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i had the same problem, add between running threads for

thread.sleep(50);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading