Answer the question
In order to leave comments, you need to log in
How to find where NullReferenceException is?
Good afternoon.
Tell me how to catch the elusive null?
There is a program with this method:
private async Task checkFile(string path)
{
var fileType = await getFileAsync(path);
if (fileType.FileExtension != "None")
{
try
{
if (this.filesMap == null) Console.WriteLine("Map is null");
if (path == null) Console.WriteLine("path is null");
if (fileType == null) Console.WriteLine("type is null");
this.filesMap.Add(path, fileType);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
}
Answer the question
In order to leave comments, you need to log in
Heh, so Dictinary is not thread-safe. You need either a thread-safe collection or a lock.
In FileMapper add somewhere
And try to rewrite to this
private static object locker = new object();
private async Task checkFile(string path)
{
var fileType = await getFileAsync(path);
if (fileType.FileExtension != "None")
{
lock(locker){
this.filesMap.Add(path, fileType);
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question