c# - APM, EAP and TPL on Socket Programming -


i found difference between […]async , begin[…] .net asynchronous apis question this answer confused me little bit.

talking these patterns, stephen said:

most *async methods (with corresponding *completed events) using event-based asynchronous pattern. older (but still valid) begin* , end* pattern called asynchronous programming model.

the socket class exception rule; *async methods not have corresponding events; it's apm done in way avoid excessive memory allocations.

i using *async methods more efficient, @ least when comes sockets. mentioned task parallel library:

however, both apm , ebap being replaced more flexible approach based on task parallel library. since tpl can wrap apms easily, older classes not updated directly; extension methods used provide task equivalents old apm methods.

i found tpl , traditional .net asynchronous programming on msdn, know basics of tpl, creating tasks, cancellations, continuations, etc still fail understand these:

what advantages of asynchronous programming model (apm) , event-based asynchronous pattern (eap) compared each other? how tpl can wrap apms easily mean both apm , eap being replaced with tpl?

and importantly: should use in socket programming;

  • apm?
  • eap?
  • apm or eap wrapped task?
  • tpl using blocking methods of socket class in tasks?
  • other?

how tpl can wrap apms mean both apm , eap being replaced tpl?

it doesn't. wether apm , eap replaced tap (task asynchronous pattern) or not in new apis has nothing this. expect tap replace apm , eap variety of reasons. main reason me code write using tap composes better. doing .continuewith(/* ... */).continuewith(/* ... */) reads better corresponding code need write chain async calls through begin/end methods, if don't take account options can pass continuewith determine if continuation should run. tpl provides various combinators tasks, such waitall , waitany, can make scenarios easier. language support coming in c# , vb.net via async/await keywords make easier.

being able wrap apms in tap makes easier switch pattern because means don't have rewrite existing code make fit in new model.

which should use in socket programming?

i recommend using tap wrapping apm methods on socket. unless can prove overhead of wrapping begin/end methods task difference between scalable/fast enough or not, take advantage ease of coding of tap.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -