The problem is most likely related to how you capture the loop variable in the lambda expression. Remember that closures capture a variable, not a value. Thus, basically the method AddDropdownItemcan get a different value for the parameter filethan what you think. This is a well-known behavioral disclaimer with closing a loop variable .
, .
foreach (var file in new DirectoryInfo(rootDir).GetFiles().Where(z => z.LastWriteTime > DateTime.Now.AddDays(-7)))
{
if (file.ToString().Contains(".log"))
{
var capture = file;
searches.Add(new Thread(new ThreadStart(() => AddDropdownItem(capture.ToString(),search))));
}
}
. , ComboBoxItem . , . , ComboBoxItem . , , , , . , , .