ThreadPool.QueueUserWorkItem with function argument

前端 未结 4 1968
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 05:18

I am using C# 2.0 and want to call a method with a couple of parameters with the help of ThreadPool.QueueUserWorkItem, so I tried as follows:

Th         


        
4条回答
  •  一生所求
    2020-12-15 06:07

    In my case, I needed an anonymous function. i.e., write to a stream asynchronously. So I used this:

    ThreadPool.QueueUserWorkItem(state => {
        serializer.Serialize(this.stream);
        this.stream.Flush();
    });
    

提交回复
热议问题