private static readonly Dictionary<Type, Object> Dump = new Dictionary<Type, object>();
public T Get<T>() where T : class
{
return Dump.ContainsKey(typeof(T)) ? Dump[typeof(T)] as T : default(T);
}
public void Set<T>(T value) where T : class
{
Dump[typeof(T)] = value;
}
public Form1()
{
InitializeComponent();
var counter = new Counter(Log);
var thread = new Thread(counter.Start);
thread.Start();
}
public void Log(int a)
{
if (InvokeRequired)
{
Invoke(new MethodInvoker(() => Log(a)));
return;
}
Text = a.ToString();
}
* This source code was highlighted with Source Code Highlighter.
public class Counter
{
private readonly Action<int> _logger;
public Counter(Action<int> logger)
{
_logger = logger;
}
public void Start()
{
for(var i =0;;i++)
{
_logger(i);
Thread.Sleep(1000);
}
}
}
* This source code was highlighted with Source Code Highlighter.