muf icon indicating copy to clipboard operation
muf copied to clipboard

Problems on changes from outside the UI thread: System.InvalidOperationException

Open XySoftNeil opened this issue 5 years ago • 2 comments

Not so much of an issue as a warning to others. If you have a need to load your monitored document in the background from a BackgroundWorker, you may run into a sporadic error.

"System.InvalidOperationException: 'Collection was modified; enumeration operation may not execute.'"

the cure for this is to make sure you are doing all your operations in the UI thread. Or It may be that the MUF code could be changed to make sure that all operations occur on the UI thread.

XySoftNeil avatar May 20 '19 16:05 XySoftNeil

I'll need to investigate if/how we might enhance the library to help prevent this.

nathanaw avatar Apr 18 '20 15:04 nathanaw

Hi Nathan, It might work out to do an IgnoreBatch similar to an UndoBatch. In the case of the editor I am maintaining, I would set up the ignore, do the long running operations, then end the ignore. At that point, start an undo batch, and replace the old file property for the new. If you are accepting pull requests I would be willing to work on this. Thanks for this very useful package.

XySoftNeil avatar Mar 14 '22 14:03 XySoftNeil