469,590 Members | 2,500 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,590 developers. It's quick & easy.

.NET 3.0 RC1 - Update UI Thread From Background Thread

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()

Sep 9 '06 #1
0 1699

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Fernando Rodríguez | last post: by
1 post views Thread by Christopher | last post: by
8 posts views Thread by =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post: by
8 posts views Thread by =?Utf-8?B?cmFuZHkxMjAw?= | last post: by
8 posts views Thread by Justin Rich | last post: by
7 posts views Thread by =?Utf-8?B?Sm9lIFRob21wc29u?= | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.