asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -
i using winscp .net assembly uploading files. want upload multiple files asynchronous way. have created method works single upload.
public class uploadingdata { private sessionoptions _sessionoptions; private session _session; //connection etc private void onconnected() { foreach (var fileinfo in localfileslist) { var task = task.factory.startnew(() => uploadfilesasync(fileinfo)); } } private async task uploadfilesasync(string file) { string remotefilepath = _session.translatelocalpathtoremote(file, @"/", "/test_data_upload"); var uploading = _session.putfiles(file, remotefilepath, false); //when done await task.run(() => thread.sleep(1000)); } }
please suggest me correct way. thanks
you can use backgroundworker class this:
string[] images = new string[50]; foreach (var path in images) { backgroundworker w = new backgroundworker(); //50 independently async threads w.dowork += delegate (object s, doworkeventargs args) { upload(args.argument.tostring()); }; w.runworkerasync(path); }
Comments
Post a Comment