Skip to content

Instantly share code, notes, and snippets.

@jamesmanning
Created March 18, 2012 03:37
Show Gist options
  • Save jamesmanning/2068575 to your computer and use it in GitHub Desktop.
Save jamesmanning/2068575 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Threading;
class Program
{
static void Main(string[] args)
{
DoSomeWork("chunk 1");
DoSomeWork("chunk 2");
DoSomeWork("chunk 3");
}
static void DoSomeWork(string chunkName)
{
using (new SomeDisposable(chunkName))
{
Console.WriteLine("Starting to do work");
Thread.Sleep(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