ContextSwitchDeadlock was detected - CLR unable to switch contexts

I'm using VS Express and have a Windows form that uses the My.Computer.FileSystem.GetDirectories to get a list of files in a directory and then using the My.Computer.FileSystem.CopyFile to copy the files in the directory to a new location. As each file is copied I'm updating a ListBox (adding an item). After about 2-3 files the ListBox is no longer updated (even tried Refreshing the ListBox and/or Form) and if there are very many files I get the ContextSwitchDeadlock error but I can hit continue and the process will finish. Only after all of the files are copied and the process is complete does the ListBox show all of the added items. How can I get the ListBox to update after each file copy and how can I prevent the ContextSwitchDeadlock error



Answer this question

ContextSwitchDeadlock was detected - CLR unable to switch contexts