首页 > 代码库 > QueueUserWorkItem引发的闭包与变量共享

QueueUserWorkItem引发的闭包与变量共享

 

//1、
public void SaveModel(testmodel msg)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(SaveModelThread), msg);

        }
public void SaveModelThread(testmodel msg)
……
//操作内容
……

//2、错误用法XXX
public void SaveModel(testmodel msg)
        {
            ThreadPool.QueueUserWorkItem((a)=>{
             SaveModelThread(msg);

});

        }

 

 

资源:

http://www.cnblogs.com/JeffreyZhao/archive/2009/03/13/anonymous-method-false-sharing.html#!comments

 

QueueUserWorkItem引发的闭包与变量共享