We have an image loader class, which load customer image from file system by customer ID. Some how, sometimes (very few) the different customer ID has the same images which are NOT belong that customer. I think it is the singleton class cause the problem, but I cannot prove or reproduce the problem. How can I reproduce the problem??
[Serializable()]
class ImageLoader : Csla.CommandBase
{
....
private static object lockImageLoader = new object();
public static ImageLoader LoadImage(int customerID)
{
lock (lockImageLoader)
{
ImageLoader original = new ImageLoader(customerID);
// Return an instance of the image loader.
return DataPortal.Execute<ImageLoader>(original);
}
}
protected override void DataPortal_Execute()
{
// Load image from file system
System.IO.FileStream fs = null;
byte[] buffer = new byte[0];
try
{
fs = System.IO.File.Open(this._fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
fs.Close();
}
catch (Exception ex)
{
throw ;
}
this._blob = buffer;
}