Microsoft Async Framework Basics

Using Visual Studio Async CTP (version 3) I'm struggling to figure out how I can "wrap" existing code using this framework.

for instance

Using the OpenPop.NET library, I am trying to establish a connection with the pop3 server and confirm that I have a valid username and password.

So let's say I have code like this.

    public bool ConnectSync()
    {
        bool success = true;
        Pop3Client client = new Pop3Client();

        try
        {
            client.Connect("mail.server.com", 110, false);
            client.Authenticate("username", "password");
        }
        catch
        {
            success = false;
        }
        return success;
    }

And now I want to do it. Async my understanding from what I read and put together is that I get the method signature line by line

    public async Task<bool> ConnectAsync()
    {

    }

I believe that this is the correct signature because it will be a task that returns a boolean (?), And I assume that I will need to use the TaskEx.Run () method? but what, as far as I can judge by the head. Can someone point in the right direction?

+5
2

, .

- , , TaskEx.Run, .

public Task<bool> ConnectAsync()
{
    return TaskEx.Run( () =>
        {
            bool success = true;
            Pop3Client client = new Pop3Client();

            try
            {
                client.Connect("mail.server.com", 110, false);
                client.Authenticate("username", "password");
            }
            catch
            {
                success = false;
            }
            return success;
        }
    );
}
+3

, , CTP, . ConnectSync async CTP:

// Note: not an async method in itself
public Task<bool> ConnectAsync()
{
    return Task.Factory.StartNew<bool>(ConnectSync);
}

(, - .)

, . , , , , . , async, , / POP3 , ConnectAsync .

+3

All Articles