Created
March 18, 2012 03:41
-
-
Save jamesmanning/2068597 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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