c# - Advantages or alternatives to asynchronous events in my case of many subscribers -
Assuming that I have a class Of course there are only 1 Every item can be used multiple times to get a change, there is a Let's say I have a lot of customers, like 100 or 1000. Each handling can delay the loop behind the time and the variable is the idea: make the event unattainable. In this case No matter how long the handler needs. However, in this question: no asynchronous events have been changed (except if there is a good performance reason). I did a little demonstration test I created a I used a I used many handler 1 handler 2 handler 3 Handler 4 I think In most cases Handler 2 is used (any complex method requires some time) and sometimes UI handler 3 or 4. Mainly because handler 2, an async event handling seems to be fast. However, I do not feel comfortable to use asynchronous events except for performance, is there any other good benefit? Or what are the options for this? What are the possible ways of dealing with this situation? Asynchronous event publication can help, but it can also increase new issues, for example, what Happens when publishers accelerate the event, so they can be consumed in comparison to the customers? In fact, you have raised problems so far that publishers are caught trapping consumers with queued notifications. This can be particularly problematic if some consumers require a UI thread, which means that further events will be sent / received. The worst case is that you can blow air into an effective standoff situation where the thread pool and / or message pump is filled with messages so that everything is slowed down in a crawl. Consider a practical note for your particular application even if it could compile the list of 'changed items' and understand more and send an event for the whole set after each update cycle. Could Since you have thousands of items, possibly changing somewhat often, this cycle can greatly reduce the number of callbacks per event. item the value of the item is taken from the external source. For at least the recent price, you have to request as much value as possible in the loop.
item , there are thousands. It looks like:
while (active) {foreach (item item item) {item.Value = RequestValue (item.Address); }}
value change in
value , where You can subscribe.
SyncItem and
asyncItem and a
subscriber .
SyncItem is calling
OnValueChanged and
AsyncItem is calling
new thread ((= => ONValueChanged ();}). (); If a value has changed.
timer to change prices (to increase incidents) I used a fast test (every 50ms) and a slow test (3s) Done
subscribers with the following handlers:
// nothing / slow test: sync fast / quick test: sync is fast, async flowed out of window closure application
Thread . Sleep (...); // slow test: synchronization slows down as much time, async // is equal to ~ 10 ms / Fast Test: Times vary, async completion window is not out of the application
Dispacrkbijininvok (new Action (() = & gt; {control.Text = value;})); // slow test synchronization is fast (handler requires Asaiansi more than 1 time) // Fast Test: Both UI does not react properly, Async UI also rarely
Dispatcher. Invoke (() => {control.Text = value;}); // Slow test: Async is fast, synchronization test: UI does not react properly / Fast Test: Sync UI does not react properly, async Autofmmeri Aksposn
Comments
Post a Comment