It is possible to use Tasks
as recommended by Miguel Anelo and do in a simplified way without worrying about the mechanism:
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
public class Program {
public static void Main() {
var lstObj = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
Parallel.ForEach(lstObj, obj => MetodoX(obj));
Console.WriteLine("Fim"); //aqui poderia ser o MetodoY()
}
public static void MetodoX(int obj) {
Console.WriteLine($"ThreadID: {Thread.CurrentThread.ManagedThreadId, 3}, Valor: {obj}");
}
}
Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.
In general it is not recommended to use Threads
rough until there’s a good reason to use.