public class SampleData
{
private static readonly Semaphore pool = new Semaphore(0,1);
public string Data => getFromFile();
private static string getFromFile()
{
pool.WaitOne();
var data =
File.ReadAllText("somefilepath");
pool.Release();
return data;
}
}
In program.cs
var tasks = new List<Task<string>>();
for(int i=0; i<=5; i++)
{
tasks.Add(Task.Run<string>(()=>
new SampleData().Data));
}
Task.WaitAll(tasks.ToArray());
When I run this, it never completes the tasks. Can any one tell me what's the issue here?
Thanks.