Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a WPF MVVM prism application to Upload files.
Me listed filed from a directory into a datagrid and 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 wanted to extend
this functionality in asynchronous way.
using delegate

this is my asynchronous fuction call

asyncUpload.BeginInvoke(selectedFiles, out tt, new AsyncCallback(test), null);<br />

Here the selected files is 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 datagrid to upload
that Will changes the first thread's selected files.


I cant keep the selected files in a variable.when the selection changed the variable value also changed.

How can I solve this.?

Thanks in advance...
Posted
Updated 14-Jul-11 2:09am
v2

1 solution

Just a general advice: when you use threads, all asynchronous API has little sense because they only make things more complex without any benefits. You need to use BeginInvoke from a non-UI thread, but as the execution in this thread does not block your UI thread, you can always do a blocking call Invoke. The cost of using non-UI thread is using Dispatcher.Invoke or Dispatcher.BeginInvoke because you cannot call anything on UI from non-UI thread, but you're doing it anyway.

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900