This article is a mirror article of machine translation, please click here to jump to the original article.

View: 24151|Reply: 3

[Source] C# is prone to problems when passing multiple parameters in a loop multithread

[Copy link]
Posted on 8/5/2016 1:40:06 PM | | | |


Today, when I was looping through multithreading, I found a problem, that is, when I looped through multithreading, there was a deviation between the value passed in and the value received by the method, why??? As follows:



Then, I searched from the Internet, and I found a solution, why didn't it appear before??? Or is it not found?????

Finally, write a test demo as follows:





I found that test1 has many errors, test2 has not had this problem,

The int type is a value type, and string is a special reference type, so this problem should not occur.

Until now, I don't know why this is the case, this article is dedicated to people who often operate multithreading。。。。。。




Previous:ASP.NET MVC modifies the Shared default path of the view (MVC2, MVC3)
Next:Asp.Net cache
Posted on 9/13/2016 1:35:11 PM |
Has the landlord's problem been solved?
 Landlord| Posted on 9/13/2016 1:37:44 PM |
nicky0510 Posted on 2016-9-13 13:35
Has the landlord's problem been solved?

If you solve the problem of passing the object in, there will be no problem
 Landlord| Posted on 9/13/2016 1:38:40 PM |
nicky0510 Posted on 2016-9-13 13:35
Has the landlord's problem been solved?

Passing a class to a class solves this problem
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com