event-handling

How to deal with race conditions in event listeners and shared state?

谁说胖子不能爱 提交于 2020-04-18 05:47:54
问题 I have 2 event listeners that operate on the same shared data/state. For instance: let sharedState = { username: 'Bob', isOnline: false, }; emitter.on('friendStatus', (status) => { sharedState.isOnline = status.isOnline; }); emitter.on('friendData', (friend) => { if (sharedState.isOnline) { sharedState.username = friend.username; } }); My problem is that these events are emitted at any order. The friendData event might come in before the friendStatus . But friendData does something with the

Get name of window which is being closed using automation events c#

安稳与你 提交于 2020-04-15 15:32:14
问题 I'm working on a project where I need to get the name of windows which is being closed . I'm using C# Automation events for this. I've pasted below the code that I'm using: Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, AutomationElement.RootElement, TreeScope.Subtree, (sender, eve) => { AutomationElement winElemnt = sender as AutomationElement; if (winElemnt != null) { Console.WriteLine("Window closed : " + winElemnt.Current.Name); } }); The above code get triggered

Get name of window which is being closed using automation events c#

女生的网名这么多〃 提交于 2020-04-15 15:32:08
问题 I'm working on a project where I need to get the name of windows which is being closed . I'm using C# Automation events for this. I've pasted below the code that I'm using: Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, AutomationElement.RootElement, TreeScope.Subtree, (sender, eve) => { AutomationElement winElemnt = sender as AutomationElement; if (winElemnt != null) { Console.WriteLine("Window closed : " + winElemnt.Current.Name); } }); The above code get triggered

EventBus/PubSub vs (reactive extensions) RX with respect to code clarity in a single threaded application

拥有回忆 提交于 2020-03-12 06:57:31
问题 Currently, I am using an EventBus/PubSub architecture/pattern with Scala (and JavaFX) to implement a simple note organizing app (sort of like an Evernote client with some added mind mapping functionality) and I have to say that I really like EventBus over the observer pattern. Here are some EventBus libraries : https://code.google.com/p/guava-libraries/wiki/EventBusExplained http://eventbus.org (currently seems to be down) this is the one I am using in my implementation. http://greenrobot

EventBus/PubSub vs (reactive extensions) RX with respect to code clarity in a single threaded application

跟風遠走 提交于 2020-03-12 06:57:08
问题 Currently, I am using an EventBus/PubSub architecture/pattern with Scala (and JavaFX) to implement a simple note organizing app (sort of like an Evernote client with some added mind mapping functionality) and I have to say that I really like EventBus over the observer pattern. Here are some EventBus libraries : https://code.google.com/p/guava-libraries/wiki/EventBusExplained http://eventbus.org (currently seems to be down) this is the one I am using in my implementation. http://greenrobot

MatCheckbox preventDefault() and event.checked value

若如初见. 提交于 2020-03-02 09:16:30
问题 How can I achieve a Material checkbox so It won't get checked/unchecked by default (eg. calling preventDefault() on the event) and also get the checked value from the event? It seems like I can only achieve one of the conditions. Using the (click) event I cannot get the checkbox's value and using the (change) event I can't prevent the default checkbox value change (I will only change the checkbox value if the underlying HTTP request was successful). Stackblitz: https://stackblitz.com/edit

Event handler incrementing loop issue

﹥>﹥吖頭↗ 提交于 2020-03-02 04:20:09
问题 I'm using Xamarin.Forms to create a chatbot app. Any time I send a new message to the bot, the reply is gotten but increments itself by one i.e User: Hi Bot: Hello User: How are you? Bot: Good Bot: Good In the code I'm using this: public void Send() { if (!string.IsNullOrEmpty(TextToSend)) { //This adds a new message to the messages collection Messages.Add(new ChatMessageModel() { Text = TextToSend, User = App.User }); //This gets the chatbots response for each message chatbot.MainUser

WPF multiple filters CollectionViewSource, first filter added works correctly, second filter added does not

萝らか妹 提交于 2020-02-27 09:05:53
问题 I have a ListView that is bounded to a CollectionViewSource. I followed this article (refered to by many) for multiple filtering: http://www.zagstudio.com/blog/456#.UG8r6E1lWLE I have two checkboxes set up for testing that do nothing but add a filter. Whenever I click on either one first, the filter is added to the CollectionViewSource and it works. Then when I click on the opposite checkbox, instead of the other filter being added to the CollectionViewSource and both filters working, my

How to check membership of an event handler from outside the owning class?

雨燕双飞 提交于 2020-02-25 09:19:31
问题 This question asks if there is a way to find if the code has already added its own event handler to an event. However, the answers given only work from inside the same class that own the event. ( Delegate.GetInvocationList and others.) I want to add a custom event handler to AppDomain.CurrentDomain.AssemblyResolve . Is there a way to find out if my custom handler is already added before adding it again? (For this and other standard library events.) If the answer is indeed "That's impossible."

How to check membership of an event handler from outside the owning class?

纵饮孤独 提交于 2020-02-25 09:19:07
问题 This question asks if there is a way to find if the code has already added its own event handler to an event. However, the answers given only work from inside the same class that own the event. ( Delegate.GetInvocationList and others.) I want to add a custom event handler to AppDomain.CurrentDomain.AssemblyResolve . Is there a way to find out if my custom handler is already added before adding it again? (For this and other standard library events.) If the answer is indeed "That's impossible."