Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help with Dispatcher.BeginInvoke

I am trying to call a method that started on a background thread on the UI thread calling BeginInvoke and passing in a delegate as follows:

Dispatcher.BeginInvoke(Function() UpdateApplicationDataUI()) 

to call this method:

Private Sub UpdateApplicationDataUI()
...
End Sub

However, I get an error in the call to BeginInvoke (the UpdateApplicationDataUI portion of the delegate is stating "Expression does not produce a value"). I'm sure I'm missing something simple...any ideas?

Did more research and answered my own question:

Me.Dispatcher.BeginInvoke(Function() New Action(AddressOf UpdateApplicationDataUI))
like image 216
Matthew Pitts Avatar asked Aug 27 '11 06:08

Matthew Pitts


People also ask

What is dispatcher BeginInvoke?

BeginInvoke(DispatcherPriority, Delegate) Executes the specified delegate asynchronously at the specified priority on the thread the Dispatcher is associated with. BeginInvoke(Delegate, DispatcherPriority, Object[])

What does dispatcher invoke do?

Invoke(DispatcherPriority, TimeSpan, Delegate)Executes the specified delegate synchronously at the specified priority and with the specified time-out value on the thread the Dispatcher was created.

What is Dispatcher c#?

The Dispatcher maintains a prioritized queue of work items for a specific thread. When a Dispatcher is created on a thread, it becomes the only Dispatcher that can be associated with the thread, even if the Dispatcher is shut down.

What is the difference between Invoke and BeginInvoke method in C#?

Invoke : Executes on the UI thread, but calling thread waits for completion before continuing. Control. BeginInvoke : Executes on the UI thread, and calling thread doesn't wait for completion.


1 Answers

I think the syntax in VB.net for this is

Dispatcher.BeginInvoke(Sub() UpdateApplicationDataUi())
like image 180
Random Dev Avatar answered Oct 01 '22 04:10

Random Dev