c# - Advantages or alternatives to asynchronous events in my case of many subscribers -


Assuming that I have a class 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.

Of course there are only 1 item , there are thousands. It looks like:

  while (active) {foreach (item item item) {item.Value = RequestValue (item.Address); }}   

Every item can be used multiple times to get a change, there is a value change in value , where You can subscribe.

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 SyncItem and asyncItem and a subscriber . SyncItem is calling OnValueChanged and AsyncItem is calling new thread ((= => ONValueChanged ();}). (); If a value has changed.

I used a timer to change prices (to increase incidents) I used a fast test (every 50ms) and a slow test (3s) Done

I used many subscribers with the following handlers:

handler 1

  // nothing / slow test: sync fast / quick test: sync is fast, async flowed out of window closure application   

handler 2

  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   

handler 3

  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   

Handler 4

  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   

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.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -