dispatcher

System.Windows.Threading.Dispatcher and WinForms?

烈酒焚心 提交于 2019-11-26 12:32:12
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 Control.BeginInvoke() , but it seems clumsy to create a control only to reference the originating thread. You can use Dispatcher even in a WinForms app. If you are sure to be on a UI thread (e.g. in an button.Click handler), Dispatcher.CurrentDispatcher gives you the UI thread dispatcher that you can later use to dispatch from background threads to the

WPF BackgroundWorker vs. Dispatcher

百般思念 提交于 2019-11-26 12:00:57
问题 In my WPF application I need to do an async-operation then I need to update the GUI. And this thing I have to do many times in different moment with different oparations. I know two ways to do this: Dispatcher and BackgroundWorker. Because when I will chose it will be hard for me to go back, I ask you: what is better? What are the reasons for choosing one rather than the other? Thank you! Pileggi 回答1: The main difference between the Dispatcher and other threading methods is that the

Dispatcher.CurrentDispatcher vs. Application.Current.Dispatcher

北城以北 提交于 2019-11-26 10:22:33
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 the current application, while Dispatcher.CurrentDispatcher may create a new instance of Dispatcher depending on the thread from which it was called. Is that correct? If it is, is the purpose of Dispatcher.CurrentDispatcher primarily for multi-threaded UI? My gut tells me that Application.Current.Dispatcher will never change and is global to all

WPF Dispatcher {“The calling thread cannot access this object because a different thread owns it.”}

[亡魂溺海] 提交于 2019-11-26 09:53:18
问题 first I need to say that I´m noob with WPF and C#. Application: Create Mandelbrot Image (GUI) My dispatcher works perfectly this this case: private void progressBarRefresh(){ while ((con.Progress) < 99) { progressBar1.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate { progressBar1.Value = con.Progress; } )); } } I get the Message (Title) when tring to do this with the below code: bmp = BitmapSource.Create(width, height, 96, 96, pf, null, rawImage, stride); this.Dispatcher.Invoke

Using the C# Dispatcher

醉酒当歌 提交于 2019-11-26 09:26:17
问题 I\'m building a chat client and am not 100% sure on how to use the dispatcher . So the question is I have a method as such: public void LostConnection() { myGUI.chatBox.AppendText(\"Lost connection to room: \"+ myGUI.UsernameText.ToString() + \"\\r\\n\"); } Do i need to surrond the statement within (myGUI.chatBox... ) with a Dispatcher.Invoke ? I appreciate any help. 回答1: Your app has a main UI thread (usually ManagedThreadId==1 ). Typically in a chat app your events will come in on other

Correct way to get the CoreDispatcher in a Windows Store app

风格不统一 提交于 2019-11-26 08:48:43
问题 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 way Windows.ApplicationModel.Core.CoreApplication.GetCurrentView().CoreWindow.Dispatcher; // Second way Window.Current.Dispatcher; I wonder which one is correct? or if both are equivalent? 回答1: This is the preferred way: Windows.ApplicationModel.Core

No WebApplicationContext found: no ContextLoaderListener registered?

耗尽温柔 提交于 2019-11-26 08:31:42
I'm trying to create a simple Spring 3 application and have the following files. Please tell me the reason for this error Below is my web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>Spring2</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>

How to pass the UI Dispatcher to the ViewModel

限于喜欢 提交于 2019-11-26 07:56:33
问题 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 instances create a global dispatcher singleton that will be written by the View? How do you solve this in your MVVM applications and frameworks? EDIT: Note that since my ViewModels might be created in background threads I can\'t just do Dispatcher

Run code on UI thread in WinRT

ε祈祈猫儿з 提交于 2019-11-26 07:39:46
How can I run code on the UI thread in WinRT (Windows 8 Metro)? The Invoke method does not exist. Cœur It's easier to directly get the CoreWindow from the non-UI thread. The following code will work everywhere, even when GetForCurrentThread() or Window.Current returns null . CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, <lambda for your code which should run on the UI thread>); for example: CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Your UI update code goes here! }); You'll need to reference Windows

Using the WPF Dispatcher in unit tests

坚强是说给别人听的谎言 提交于 2019-11-26 06:29:19
问题 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 ThreadStart(delegate { this.Users.Clear(); foreach (User user in e.Results) { this.Users.Add(user); } }), DispatcherPriority.Normal, null); I have this code in my viewmodel base class to get a Dispatcher: if (Application.Current != null) { this.Dispatcher