Hello All,
Using the following delegate, and attempting to update the UI. There is no
clear examples on how to pass multiple parameters though to the dispatcher.
I keep receiving an exception (shown below). The code works if you invoke a
method that only has one parameter, however it should work with multiple
parameters. Maybe I am missing something simple.
-------------- CODE FOLLOWS --------------
Public Delegate Sub MemberChatDelegate(ByVal member As String, ByVal msg As
String)
Public Sub UpdateChat(ByVal member As String, ByVal msg As String)
' Update UI Code here
If Me.Dispatcher.CheckAccess Then
' Update UI Code
Else
Me.Dispatcher.Invoke(Windows.Threading.DispatcherP riority.Normal,
New MemberChatDelegate(AddressOf UpdateChat), New ChatMessage(member, msg),
Nothing, New Object() {member, msg})
End If
'
End Sub
-------------- EXCEPTION FOLLOWS --------------
System.Reflection.TargetParameterCountException was unhandled
Message="Parameter count mismatch."
Source="mscorlib"
StackTrace:
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.Internal RealCall(Delegate callback,
Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatch When(Object
source, Delegate callback, Object args, Boolean isSingleParameter, Delegate
catchHandler)
at System.Windows.Threading.DispatcherOperation.Invok eImpl()
at
System.Windows.Threading.DispatcherOperation.Invok eInSecurityContext(Object
state)
at System.Threading.ExecutionContext.runTryCode(Objec t userData)
at
System.Runtime.CompilerServices.RuntimeHelpers.Exe cuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(Exec utionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invok e()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(In tPtr 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.Internal RealCall(Delegate callback,
Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatch When(Object
source, Delegate callback, Object args, Boolean isSingleParameter, Delegate
catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(Dis patcherPriority
priority, TimeSpan timeout, Delegate method, Object args, Boolean
isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(Dispatc herPriority
priority, Delegate method, Object arg)
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(Disp atcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at App.Main() in C:\Documents and Settings\Luke\Desktop\Windows
Vista\Projects\Live Help Application\Live Help
Application\obj\Debug\App.g.vb:line 60
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()