воскресенье, 7 марта 2010 г.

What I’d like to see in C# 5.0

Axum, an experimental language, has such a feature as async methods. In such methods interaction with  interaction points and APM based API happens asynchronously.
Besides that there are signs that in the future C# will support resumable methods. Luca Bolognese opened up some details at the PDC 2009 session Future of C# and VB. Fast-forward to 50:00 where he shows experimental yield keyword in the method returning Async<T>.
That’s great news because with what we have now  if you want to make long running call not keeping your thread waiting/doing nothing/consuming  memory you have to put all your logic in callback methods calling each other. With resumable methods such code would be much  easier to write, read and refactor, and the exception handling would look like  synchronous, stack based.

But being excited about the feature:

  • I don’t like the idea of introducing a new type (Async<T>) when we already have Task and Task<T> types
  • I’d like C# to recognize not only APM pattern based API but methods and properties that return Task or Task<T> as well. If you compare Task and IAsyncResult you’ll see that a Task based asynchronous API is much simpler, cleaner and easier to implement. Compare the next two variations:

    //Task based API
    public Task  UploadData(string uri, string data)  { … }
    public Task<string> DownloadData(string uri) { … }
    public Task<int> TotalNumberOfRows { get { … } }

    //APM based API
    public IAsyncResult BeginUploadData(string uri, string data, AsyncCallback callback, object context)  { … }
    public void EndUploadData(IAsyncResult ar)

    public IAsyncResult BeginDownloadData(string uri, AsyncCallback callback, object context) { … }
    public string EndDownloadData(IAsyncResult ar)

    public IAsyncResult BeginGetTotalNumberOfRows(AsyncCallback callback, object context) { … }
    public int EndGetTotalNumberOfRows(IAsyncResult ar)

  • I’d like C# to recognize extension methods that implement APM or Task based API

2 комментария:

  1. Such a wonderful post. C# Development is one of the most popular application development now-a-days. We are also providing some good tips related to this post.Great work.

    ОтветитьУдалить
  2. thanks for your valuable information it is helpful for me, i like to share you something
    http://traininginmedavakkam.in/training-courses/aws-training-in-medavakkam/
    http://traininginmedavakkam.in/training-courses/java-training-in-medavakkam/
    http://traininginmedavakkam.in/training-courses/oracle-training-in-medavakkam/
    http://traininginmedavakkam.in/training-courses/python-training-in-medavakkam/
    http://traininginmedavakkam.in/training-courses/sap-hr-training-in-medavakkam/
    http://traininginmedavakkam.in/training-courses/php-training-in-medavakkam/
    http://traininginmedavakkam.in/training-courses/selenium-training-in-medavakkam/
    http://traininginmedavakkam.in/training-courses/big-data-training-in-medavakkam/
    http://traininginmedavakkam.in/training-courses/sap-abap-training-in-medavakkam/
    http://traininginmedavakkam.in/training-courses/ccnp-training-in-medavakkam/

    ОтветитьУдалить