dispatcher

wpf: update multiple controls via dispatcher

我们两清 提交于 2019-12-12 21:16:13
问题 I'm reading data from a serial port using an event listener from the SerialPort class. In my event handler, I need to update many (30-40) controls in my window with xml data coming over the serial port. I know that I must use myControl.Dispatcher.Invoke() to update it since it's on a different thread, but is there a way to update lots of controls together, rather than doing a separate Invoke call for each (i.e. myCon1.Dispatcher.Invoke(), myCon2.Dispatcher.Invoke(), etc)? I'm looking for

WPF Are NotifyPropertyChangeds marshalled to the dispatcher?

≡放荡痞女 提交于 2019-12-12 19:03:58
问题 If I update a property that throws a NotifyPropertyChanged on a thread other than the bound control's dispatcher is the update forcibly marshalled to this dispatcher? BackgrounWorker.Run() => { blah.Blahness = 2; // notifies property changed on BW, is this marshalled to the dispatcher? } 回答1: Yes, the PropertyChanged event is automatically marshalled to the UI dispatcher, so you don't need to use Invoke to marshall it explicitly. Note that it is only true for change notifications on scalar

NMock issue testing against WPF and Dispatcher

僤鯓⒐⒋嵵緔 提交于 2019-12-12 18:35:54
问题 Here's one for the threading junkies out there. I've got this method: public void RefreshMelts() { MeltsAvailable.Clear(); ThreadPool.QueueUserWorkItem(delegate { Dispatcher.BeginInvoke((ThreadStart)delegate { eventAggregator.GetEvent<BusyEvent>().Publish(true); eventAggregator.GetEvent<StatusMessageEvent>().Publish( new StatusMessage("Loading melts...", MessageSeverity.Low)); }); try { IList<MeltDto> meltDtos = meltingAppService.GetActiveMelts(); Dispatcher.Invoke((ThreadStart)delegate {

In WPF, how to set a Window Owner of a Window build on another thread (another Dispatcher)

落爺英雄遲暮 提交于 2019-12-12 16:04:42
问题 I got the following exception: InvalidOperationException : The calling thread cannot access this object because a different thread owns it. when I try to set the Owner of a window that is build on another thread than the Owner. I know that I can only update UI object from the proper thread, but why I can't just set the owner if it come from another thread? Can I do it on another way ? I want to make the progress window the only one which can have input entries. This is the portion of code

Is it possible to recursively flush directories in the CQ5/AEM apache dispatcher?

无人久伴 提交于 2019-12-12 08:43:30
问题 I have a dispatcher set up with a fairly deep stats file level due to a particular project in a multi tenancy situation. What I'm hoping is for a way to be able to recursively flush directories to mimic a more shallow stats file level for the other tenants. Is there a dispatcher flush command that allows me to explicitly delete a directory of content? 回答1: You could achieve this yourself by sending a simple GET request to your dispatcher. The path on the Dispatcher that you need to hit is

Best/cleanest strategy to update an ObservableCollection from another thread

醉酒当歌 提交于 2019-12-12 05:56:31
问题 Normally I check if I have access to the ObservableCollection and if not, I call a Dispatcher . Here (on Stackoverflow ) are also some other solutions, but I don't know what is the best and cleanest way. I think my solution is obsolete and should not be used anymore. In my example is the ItemsCollection bound to the UI . The _UpdateTheCollectionFromAnotherThread() would being called (from another thread or would open another thread ) and save the data temporary to items . After that I would

View is not updated when on a separate thread

若如初见. 提交于 2019-12-12 05:36:59
问题 I am trying to load some data in a separate thread, then add the loaded data to an ObservableCollection and update the view through ba binding. First, I was doing the following: public OverviewViewModel() { Thread thread = new Thread(new ThreadStart(delegate { TheTVDB theTvdb = new TheTVDB(); foreach (TVSeries tvSeries in theTvdb.SearchSeries("Dexter")) { this.Overview.Add(tvSeries); } })); thread.SetApartmentState(ApartmentState.STA); thread.Start(); } This gave the following error: This

WPF Dispatcher and Running it in background

谁说胖子不能爱 提交于 2019-12-12 04:50:58
问题 I tried to wrap the dispatcher in a thread. But the result is not what i expect. How can i solve that problem? public void Start() { ThreadStart ts = inner; Thread wrapper = new Thread(ts); wrapper.Start(); } private void inner() { _Runner.Dispatcher.Invoke(_Runner.Action, DispatcherPriority.Normal); } 回答1: You have not shown us enough code/explained yourself well enough to be able to provide a good answer, but I'm guessing your action ( _Runner.Action ) is expensive and slow to execute. If

Dispatcher.Invoke loop freeze UI

心已入冬 提交于 2019-12-12 04:07:18
问题 I have log tailing app which is executing Background worker thread in infinitive loop and checking for latest entries inside some TXT file. Once it find new entries I use Dispatcher.Invoke to update TextBox on the screen with latest entry added to the text file. The problem is that if the source text file is being updated constantly every millisecond the user interface is just freezing since Dispatcher.Invoke is updating Textbox so often. Wonder if there is any workaround. I could get bigger

Task.ContinueWith and DispatcherSynchronizationContext

烈酒焚心 提交于 2019-12-11 20:32:05
问题 I'm facing an issue that I do not understand when unit testing a code that uses task continuation and DispatcherSynchrinizationContext. My unit test code : [TestClass] public class UnitTest1 { [TestMethod] public void TestMethod1() { SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext()); var class1 = new Class1(); var result = class1.MyAsyncMethod().Result; Assert.IsTrue(result == "OK"); } } The code that is being tested : class Class1 { public Task<string>