Home Ask Login Register

Developers Planet

Your answer is one click away!

james February 2016

Convert InvokeRequired to Dispatch in VB WPF

Hello I'm stuck on the last section of my code in which I'm converting from standard VB to VB WPF I was originally using invoke commands but I'm struggling to use them within VB WPF. Currently I'm on the final two lines but I just can't seem to figure out how to rewrite it, could you possibly help?

 If Me.InvokeRequired Then
        Me.Invoke(New MethodInvoker(AddressOf AccessPicture))

I'm using VB WPF


Ahmad Alloush February 2016

You can know if invocation is required by checking if the current thread is the UI thread and then invoke the dispatcher thread if it's required here I give you an example in c# and it's totally the same logic in VB

public void EventHandler(object object,EventArgs e)
if (this.Dispatcher.Thread != System.Threading.Thread.CurrentThread)
 // invoke using this.Dispatcher.Invoke(new EventHandler(EventHandler),object,e)
   //execute your code

Post Status

Asked in February 2016
Viewed 2,962 times
Voted 12
Answered 1 times


Leave an answer

Quote of the day: live life