0
的代码抛出ManualResetEvent的抛出的NullReferenceException:对象没有设置为一个对象
的NullReferenceException的一个实例:不设置为一个对象
的实例就行((ManualResetEvent)handles[i]).Set()
对象引用。我检查手柄[我]有一个值,当我调试它。我究竟做错了什么?
` string[] fileEntries = Directory.GetFiles(pathFife);
ManualResetEvent[] handles = new ManualResetEvent[fileEntries.Count()];
int i = 0;
foreach (string fullName in fileEntries)
{
handles[i] = new ManualResetEvent(false);
var thread = new Thread(() =>
{
AddFile(fullName, month, year, user);
((ManualResetEvent)handles[i]).Set();
});
thread.Start();
i++;
}
WaitHandle.WaitAll(handles);`
@Downvoter:小心解释这个答案有什么问题?否则,downvote对任何人都不是很有帮助。 –