Custom awaitable and awaiter types in C# 5.0 asynchronous

In C# 5.0 you can use the await keyword to await an awaitable object. But what is the minimum requirement for an object to be considered awaitable by C#? Interestingly there are no interfaces to be implemented in order to be considered awaitable!
Having a parameter-less method named GetAwaiter() which returns an awaiter object is the only convention for a type to be recognized awaitable by C#:

// This class is awaitable because it has the GetAwaiter method, provided MyAwaiter is an awaiter.
public class MyWaitable
{
    public MyAwaiter GetAwaiter()
    {
        return new MyAwaiter();
    }
}

Now the question is how to make a type awaiter? The minimum requirements for a type to be awiater are implementing the INotifyCompletion interface, and having the IsCompleted property and the GetResult method with the following signatures:

public class MyAwaiter : INotifyCompletion
{
    public void OnCompleted(Action continuation)
    {
        
    }

    public bool IsCompleted
    {
        get
        {
            return false;
        }
    }


    public void GetResult()
    {
       
    }
}
Advertisements

Batch edit TeamCity build configurations

TeamCity supports parameters, so if you are dealing with so many build configurations on your TeamCity server and you need to change something in all of your projects, the best practice is to use parameters or build templates. But what if you need to change a value in multiple build configurations or multiple projects and that value cannot be (or is not) defined as a parameter? In such cases you can use the following shortcut instead of going through each build configuration to edit them:

  1. On the TeamCity machine, open the data directory. It can be identified using the TEAMCITY_DATA_PATH environment variable.
  2. Open the corresponding directory to your required project from %TEAMCITY_DATA_PATH%\config\projects.
  3. All of the build configurations are stored as XML files in the buildTypes directory.
  4. Use a powerful text editor (e.g. Notepad++ ) to batch edit the files.
  5. From the TeamCity administration page, go to Server Administration\Diagnostics\Caches and reset buildsMetadata.

After a couple of seconds the changes should be reflected in all of your build configurations.