Project: Threading.Instance.Variables



Access to instance varibles from an external thread:
public delegate void MyDelegate();

public Customer[] customerArray = 
	new []
		{ 
			new Customer { Name = "Bill" } 
		};
		
public int[] numberArray = new [] { 5, 2 };
	
void Main()
{
	Thread.CurrentThread.ManagedThreadId.Dump("Main thread: ");
	var myDelegate = new MyDelegate(Method);
	
	myDelegate.BeginInvoke(null, null);
}

public void Method()
{
	Thread.CurrentThread.ManagedThreadId.Dump("Delegate thread: ");
	numberArray[0].Dump();
	customerArray[0].Dump();	
}

public class Customer 
{ 
	public string Name { get; set; } 
}

Last edited Mar 30, 2012 at 10:52 AM by teoarch, version 1

Comments

No comments yet.