Questions tagged [dispatcher]

In WPF and Silverlight, Dispatcher is an object that is used to execute work on a specific thread. In another meaning, dispatcher defines an object that receives requests from the client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server.

In and , Dispatcher is an object that is used to execute work on a specific .

In another meaning, a dispatcher object can forward a client's request to a resource or include the resource itself in the response back to the client. A resource can be another servlet, or an HTML file, or a JSP file, etc.

1296 questions
253
votes
16 answers

Which Python packages offer a stand-alone event system?

I am aware of pydispatcher, but there must be other event-related packages around for Python. Which libraries are available? I'm not interested in event managers that are part of large frameworks, I'd rather use a small bare-bones solution that I…
Josip
  • 6,677
  • 9
  • 26
  • 27
93
votes
3 answers

Dispatcher.CurrentDispatcher vs. Application.Current.Dispatcher

What are the differences between Dispatcher.CurrentDispatcher (in System.Windows.Threading) and Application.Current.Dispatcher (in System.Windows)? My gut tells me that Application.Current.Dispatcher will never change and is global to all threads in…
qxn
  • 17,162
  • 3
  • 49
  • 72
91
votes
4 answers

Change WPF controls from a non-main thread using Dispatcher.Invoke

I have recently started programming in WPF and bumped into the following problem. I don't understand how to use the Dispatcher.Invoke() method. I have experience in threading and I have made a few simple Windows Forms programs where I just used…
D. Veloper
  • 1,497
  • 5
  • 16
  • 24
85
votes
5 answers

Correct way to get the CoreDispatcher in a Windows Store app

I'm building a Windows Store app, and I have some code that needs to be posted to the UI thread. For that, i'd like to retrieve the CoreDispatcher and use it to post the code. It seems that there are a few ways to do so: // First…
lysergic-acid
  • 19,570
  • 21
  • 109
  • 218
84
votes
5 answers

Dispatcher.BeginInvoke: Cannot convert lambda to System.Delegate

I'm trying to call System.Windows.Threading.Dispatcher.BeginInvoke. The signature of the method is this: BeginInvoke(Delegate method, params object[] args) I'm trying to pass it a Lambda instead of having to create a…
Micah
  • 111,873
  • 86
  • 233
  • 325
77
votes
16 answers

How to pass the UI Dispatcher to the ViewModel

I'm supposed to be able to access the Dispatcher that belongs to the View I need to pass it to the ViewModel. But the View should not know anything about the ViewModel, so how do you pass it? Introduce an interface or instead of passing it to the…
bitbonk
  • 48,890
  • 37
  • 186
  • 278
67
votes
6 answers

Run code on UI thread in WinRT

How can I run code on the UI thread in WinRT (Windows 8 Metro)? The Invoke method does not exist.
ofer
  • 721
  • 1
  • 8
  • 7
59
votes
2 answers

How do I get the UI thread's Dispatcher?

Is there any way to get the UI thread's Dispatcher when you have no reference to any UI elements?
Peter
  • 37,042
  • 39
  • 142
  • 198
56
votes
4 answers

Cannot convert lambda expression to type 'System.Delegate'

Neither of these work: _uiDispatcher.Invoke(() => { }); _uiDispatcher.Invoke(delegate() { }); All I want to do is Invoke an inline method on my main UI thread. So I called this on the main thread: _uiDispatcher = Dispatcher.CurrentDispatcher; And…
mpen
  • 272,448
  • 266
  • 850
  • 1,236
54
votes
16 answers

Using the WPF Dispatcher in unit tests

I'm having trouble getting the Dispatcher to run a delegate I'm passing to it when unit testing. Everything works fine when I'm running the program, but, during a unit test the following code will not run: this.Dispatcher.BeginInvoke(new…
Chris Shepherd
  • 1,436
  • 1
  • 11
  • 17
47
votes
2 answers

How to put delay before doing an operation in WPF

I tried to use the below code to make a 2 second delay before navigating to the next window. But the thread is invoking first and the textblock gets displayed for a microsecond and landed into the next page. I heard a dispatcher would do that. Here…
BharathNadadur
  • 557
  • 1
  • 6
  • 13
42
votes
1 answer

Dispatcher Invoke(...) vs BeginInvoke(...) confusion

I'm confused why I can't make this test counter application work with 2 (or more) simultaneous running countertextboxes with the use of "BeginInvoke" on my Dispatcher in the Count() method. You can solve the issue by replacing the BeginInvoke by an…
Jerev
  • 431
  • 1
  • 4
  • 6
38
votes
1 answer

Ensuring that things run on the UI thread in WPF

I'm building a WPF application. I'm doing some async communication with the server side, and I use event aggregation with Prism on the client. Both these things results in new threads to be spawned which are not the UI thread. If I attempt to do…
stiank81
  • 25,418
  • 43
  • 131
  • 202
37
votes
5 answers

c# - Volatile keyword usage vs lock

I've used volatile where I'm not sure it is necessary. I was pretty sure a lock would be overkill in my situation. Reading this thread (Eric Lippert comment) make me anxious on my usage of volatile: When should the volatile keyword be used in c# ? I…
Eric Ouellet
  • 10,996
  • 11
  • 84
  • 119
35
votes
8 answers

System.Windows.Threading.Dispatcher and WinForms?

Does a System.Windows.Threading.Dispatcher work on the UI-thread of a WinForms application? If yes, why? It is coming from WindowsBase.dll which seems to be a WPF component. If not, how can I invoke work units back onto the UI-thread? I've found…
David Schmitt
  • 58,259
  • 26
  • 121
  • 165
1
2 3
86 87