dispatcher

Ensuring that things run on the UI thread in WPF

a 夏天 提交于 2019-11-27 11:20:40
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 "WPF operations" on these callback and event handler threads the world will fall apart, which it now has started doing. First I met problems trying to create some WPF objects in the callback from server. I was told that the thread needed to run in STA mode. Now I'm trying to update some UI data in a Prism event handler, and I'm told that: The caller

Cannot convert lambda expression to type 'System.Delegate'

狂风中的少年 提交于 2019-11-27 08:11:40
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 now I want to execute some code on that thread from another thread. How do I do it? Am I using the wrong syntax? Note that this is not a WPF application; I've referenced WindowsBase so I could get access to the Dispatcher class. The problem is that you aren't providing the exact type of delegate you want to invoke. Dispatcher.Invoke just takes a

how do I convert wpf dispatcher to winforms

﹥>﹥吖頭↗ 提交于 2019-11-27 08:03:02
问题 I was moving over a method to my winforms project from a wpf project. Everything but this section was moved without issue: private void ServerProcErrorDataReceived(object sender, DataReceivedEventArgs e) { // You have to do this through the Dispatcher because this method is called by a different Thread Dispatcher.Invoke(new Action(() => { richTextBox_Console.Text += e.Data + Environment.NewLine; richTextBox_Console.SelectionStart = richTextBox_Console.Text.Length; richTextBox_Console

The calling thread cannot access this object because a different thread owns it.WPF

左心房为你撑大大i 提交于 2019-11-27 07:50:34
Whenever I refresh a label, I got this error: The calling thread cannot access this object because a different thread owns it. I tried to invoke but it's failed. I'm using WPF Form. delegate void lostfocs(string st); private void imgPayment_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Thread t = new Thread(modi); t.Start(); } void modi() { try { label1.Content = "df"; } catch { lostfocs ld = new lostfocs(up); // ld.Invoke("df"); object obj=new object(); ld.Invoke("sdaf"); } } void up(string st) { label1.Content = st; } Use Dispatcher.Invoke Method. Executes the specified

Dispatcher Invoke(…) vs BeginInvoke(…) confusion

会有一股神秘感。 提交于 2019-11-27 06:54:18
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 Invoke. But this doesn't solve my confusion. Here's the sample code I'm talking about: public class CounterTextBox : TextBox { private int _number; public void Start() { (new Action(Count)).BeginInvoke(null, null); } private void Count() { while (true) { if (_number++ > 10000) _number = 0; this.Dispatcher.BeginInvoke(new Action(UpdateText), System

WPF BackgroundWorker vs. Dispatcher

我是研究僧i 提交于 2019-11-27 06:30:30
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 The main difference between the Dispatcher and other threading methods is that the Dispatcher is not actually multi-threaded. The Dispatcher governs the controls, which need a single thread to

Is WPF Dispatcher the solution of multi threading problems?

心不动则不痛 提交于 2019-11-27 05:08:50
问题 I have a very bad feeling about using lock in my code but now the Dispatcher of WindowBase exists and I want to use it everywhere. For example I use a multi thread singleton WCF service who publish events on the EventAggregator of PRISM, the payload is immutable (it is just data) and every thread with a dispatcher can retrieve the event gracefully, whitout deadlock in their own dispatcher. (Not only UI thread, but also threads with database calls, threads with services call, threads which log

How to forward request from servlet to action of struts2?

て烟熏妆下的殇ゞ 提交于 2019-11-27 04:21:56
问题 I want to forward a request from Servlet to Action like this using RequestDispacher like this RequestDispatcher dispatcher=request.getRequestDispatcher("hello.action"); dispatcher.include(request, response); It's not working. How can I resolve this problem? 回答1: In order to do this you may also need to set the filter to run on FORWARD (and INCLUDE as your code shows, although you state you want a FORWARD): <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern>

Correct way to get the CoreDispatcher in a Windows Store app

倖福魔咒の 提交于 2019-11-27 02:47:08
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? MAXE This is the preferred way: Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Your UI update code

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

安稳与你 提交于 2019-11-27 02:04:16
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(DispatcherPriority.Send, new Action(delegate { img.Source = bmp; ViewBox.Child = img; //vllt am