我保持現有的一些頁面和System.Threading
跨位的代碼來了,我不知道該用它來做什麼。線程的奇怪場所?
(這是它的要點)
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument xmlDoc = GetFromCMS();
var nodes = xmlDoc.SelectNodes("/xpath/to/nodes");
int i = 0;
while (i < nodes.Count)
{
//do stuff with nodes[i]
//last line in while loop - this is where I'm confused
Math.Max(System.Threading.Interlocked.Increment(ref i), i - 1);
}
}
是否是有意義的做這樣的事情?而不是i
應該增加ala i++
而不是?我不是在多線程精通,但考慮到有這個頁面並沒有什麼真正的「特殊」發生(正在創建沒有額外的線程,等等)上沒有其他的線程代碼,似乎有點怪我。
感謝您的協助!
Math.Max是無用太,整個事情可以改寫爲「爲(INT I = 0; I <節點。 Count; i ++){...}' – 2011-05-26 01:16:31
@SelflessCoder你是對的,錯過了那個重構。 – 2011-05-26 01:17:52
看起來像一個剪切和粘貼錯誤 – 2011-05-26 01:18:39