Skip to content

Instantly share code, notes, and snippets.

@jamesmanning
Created March 18, 2012 03:41
Show Gist options
  • Save jamesmanning/2068597 to your computer and use it in GitHub Desktop.
Save jamesmanning/2068597 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Threading;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
var task1 = DoSomeWork("chunk 1");
var task2 = DoSomeWork("chunk 2");
var task3 = DoSomeWork("chunk 3");
Task.WaitAll(task1, task2, task3);
}
static async Task DoSomeWork(string chunkName)
{
using (new SomeDisposable(chunkName))
{
Console.WriteLine("Starting to do work");
await Task.Delay(5000);
Console.WriteLine("Finishing work");
}
}
}
public class SomeDisposable : IDisposable
{
private string m_chunkName;
public SomeDisposable(string chunkName)
{
m_chunkName = chunkName;
Console.WriteLine("Created disposable for chunk {0}!", m_chunkName);
}
void IDisposable.Dispose()
{
Console.WriteLine("Disposed disposable for chunk {0}!", m_chunkName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment