static void Main(string[] args) { int someNumber = 3; string strang = "Hello"; Person person = new Person(); person.Id = 1; person.Name = "Foo"; MyClass myClass = new MyClass(); // Do something with a number myClass.DoSomething(someNumber); // Do something with a strang (string) myClass.DoSomething(strang); // Do something with a Person object myClass.DoSomething(person); Console.ReadKey(); }
static void Main(string[] args) { var myClass = new MyClass(); lock (myClass) { var task = Task.Run(() => myClass.DoSomething()); Console.WriteLine("Waiting for the task to complete."); if (!task.Wait(1000)) { Console.WriteLine("ERROR: The task did not complete."); } else { Console.WriteLine("Task completed."); } Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }