내가 .NET에서 웹 클라이언트 클래스를 사용하여 매우 이상한 오류가 있어요에서 스레드를 사용하는 경우 4.웹 클라이언트 오류가 .NET
응용 프로그램은 단순히 인터넷으로 일부 파일을 다운로드하고 텍스트 상자에 출력을 제공 (GUI는 WPF입니다). 이 작업을 수행하는 방법은 다음과 같다 :
void DownloadFiles(object files) {
var fileL = (List<string>) files;
foreach (string url in fileL)
{
byte[] data;
using (var k = new WebClient())
{
data = k.DownloadData(url);
}
//Bunch of irrelevant code goes here...
}
}
(나는 신성을 시도하는 동안 사용하여 추가 솔루션, 문제가 WebClient를 선언하고 외부 초기화되는 경우에도 발생 [그래, 난 필사적/무지가 있다고 해요] foreach 루프)
이제는이 메서드를 WPF UI 주 스레드와 별도의 스레드에서 실행하는 경우에만 문제가 발생합니다. UI 스레드에서 실행되면 완벽하게 작동합니다. 새로운 스레드가 생성됩니다 때 :
Thread t = new Thread(DownloadFiles);
t.Start(files);
처음 코드가 작동 루프로 전환하지만 때 루프 내부의 두 번째 패스, 나는 항상 TargetParameterCountException을 받게됩니다.
이 오류는 알 수 없습니다. 어떤 도움이라도 대단히 감사합니다.
Exception.Message = "Parameter count mismatch."
Exception.InnerException = null
Exception.Source = " mscorlib"
스택 트레이스는 다음과 같습니다 : 여기에 편집
는 예외 정보입니다
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at FileDownloader.App.Main() in d:\mis documentos\visual studio 2010\Projects\OneMangaDownloader\FileDownloader\obj\x86\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
오류 (메시지, stacktrace, InnerException 세부 정보 ...)에 대한 자세한 내용을 게시하십시오 –
토마스에게 도움을 요청한 정보를 추가했습니다 –