开发者

WPF asynchronous databinding

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 pas开发者_如何转开发s 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 SelectedItems list into your BeginInvoke() method.

Instead, pass a copy of the SelectedItems list.

Array[] array = new Array[dataGrid.SelectedItems.Count];

dataGrid.SelectedItems.CopyTo(array, 0);

asyncUpload.BeginInvoke(array.ToList(), out tt, new AsyncCallback(test), null); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜