I have a WPF MVVM prism application to upload files.
I filled a datagrid with a list of files from a directory and got an upload button to upload the selected files from the datagrid.
For this I pass the grid selecteditems to the command parameter of the button.
I successfully implemented this in the synchronous way and now want to extend
this functionality in asynchronous way by using delegates.
This is my asynchronous function call:
asyncUpload.BeginInvoke(selectedFiles, out tt, new AsyncCallback(test), null);
Here the selected files are the selecteditems from the datagrid passed through the command parameter of the upload button.
The problem is that while executing the first thread for uploading, I’m selecting another set of files from the datagrid to upload that will change the first thread’s selected files.
How can I solve this?
Don’t pass the actual
SelectedItemslist into yourBeginInvoke()method.Instead, pass a copy of the
SelectedItemslist.