[C#] Stahování více souborů najednou.
Zdravím poradňáci, žádám vás o pomoc v programovacím jazyku C#.
Potřeboval bych přes 1 tlačítko stáhnout až 10 souborů, všechny mam postupně vypsané.
Problém je v tom že hned u druhého stažení to hodí Error ve tvaru:
System.NotSupportedException was unhandled
HResult=-2146233067
Message=Klient WebClient nepodporuje souběžné operace vstupu a výstupu.
Source=System
StackTrace:
v System.Net.WebClient.ClearWebClientState()
v System.Net.WebClient.DownloadFileAsync(Uri address, String fileName, Object userToken)
v System.Net.WebClient.DownloadFileAsync(Uri address, String fileName)
v FreeLance___Genesis.Form1.onClickZahajit(Object sender, EventArgs e) v C:\Users\siOnz_000\AppData\Local\Temporary Projects\FreeLance - Genesis\Form1.cs:řádek 31
v System.Windows.Forms.Control.OnClick(EventArgs e)
v System.Windows.Forms.Button.OnClick(EventArgs e)
v System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
v System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
v System.Windows.Forms.Control.WndProc(Message& m)
v System.Windows.Forms.ButtonBase.WndProc(Message& m)
v System.Windows.Forms.Button.WndProc(Message& m)
v System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
v System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
v System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
v System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
v System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
v System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
v System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
v System.Windows.Forms.Application.Run(Form mainForm)
v FreeLance___Genesis.Program.Main() v C:\Users\siOnz_000\AppData\Local\Temporary Projects\FreeLance - Genesis\Program.cs:řádek 18
v System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
v System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
v Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
v System.Threading.ThreadHelper.ThreadStart_Context(Object state)
v System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
v System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
v System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
v System.Threading.ThreadHelper.ThreadStart()
InnerException:
Kromě metody kterou jsem to udělal a nefunguje. Mě jiná nenapadá.
WebClient client = new WebClient();
client.DownloadFileAsync(new Uri("bla.bar"), "bla.jar");
client.DownloadFileAsync(new Uri("bla.bar"), "bla.jar");
Pro každé stahování si vytvoř nový WebClient.
Dobře, ale příjde mi to zbytečné, doopravdy se to takhle má dělat ?
Nedojde tak k zaseknutí ? To je jako spustit určitou hru několikrát.
No víceméně díky :) Funguje to.