Quantcast
Channel: Excel Data Reader - Read Excel files in .NET
Viewing all articles
Browse latest Browse all 448

Created Unassigned: Reading 2 excel files simultaneously gives an exception [13775]

$
0
0
I am reading two excel files simultaneously. Here is my Code

```
Parallel.Invoke(
()=>
{
FileStream stream = File.Open(@"C:\Projects\TPD.xlsx", FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
},
() =>
{
FileStream stream = File.Open(@"C:\Projects\TPD1.xlsx", FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
});
```

I am getting an Exception (An item with the same key already added) in Class LogManager Method Log, where it is trying to add a new logger in the dictionary. This issue is related to synchronization and proposed code to solve this problem is

```
public static ILog Log(string objectName)
{
ILog result = null;
lock (_sync)
{
if (_dictionary.ContainsKey(objectName) == false)
{
_dictionary.Add(objectName, Excel.Log.Log.GetLoggerFor(objectName));
}
result = _dictionary[objectName];

}
return result;
}
```

Viewing all articles
Browse latest Browse all 448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>