G
Gina_Marano
public partial class FormMain : Form
{
private static Object LockVariable = new Object();
public static SpecXMLFileNameCache aFileCache = new
SpecXMLFileNameCache();
public class SpecXMLFileNameCache
{
private Dictionary<string, bool> _SpecXMLFileNameCache;
public SpecXMLFileNameCache()
{
_SpecXMLFileNameCache = new Dictionary<string, bool>
();
}
public void AddXMLFileName(string aFileName)
{
lock(LockVariable)
{
_SpecXMLFileNameCache.Add(aFileName,false);
}
}
public void UpdateXMLFileNameStatus(string aFileName)
{
lock(LockVariable)
{
if (_SpecXMLFileNameCache.ContainsKey(aFileName))
_SpecXMLFileNameCache[aFileName] = true;
}
}
public bool ContainsXMLFileName(string aFileName)
{
lock (LockVariable)
{
bool bAlreadyObtained = false;
_SpecXMLFileNameCache.TryGetValue(aFileName, out
bAlreadyObtained);
return bAlreadyObtained;
}
}
}
....
private void btnAddSpecXMLFileName_Click(object sender,
EventArgs e)
{
if (eAddSpecXMLFileName.Text.Trim() != "")
{
aFileCache.AddXMLFileName(eAddSpecXMLFileName.Text);
}
}
}
}
The user will add items to this list via the GUI. A background thread
is running that will have an external list of files. It will see if
the file name is in the list above and hasn't yet been downloaded. If
this is the case it will download the file and update the item in the
list as downloaded.
Are there any threading issues here?
Thanks
~Gina_M~
{
private static Object LockVariable = new Object();
public static SpecXMLFileNameCache aFileCache = new
SpecXMLFileNameCache();
public class SpecXMLFileNameCache
{
private Dictionary<string, bool> _SpecXMLFileNameCache;
public SpecXMLFileNameCache()
{
_SpecXMLFileNameCache = new Dictionary<string, bool>
();
}
public void AddXMLFileName(string aFileName)
{
lock(LockVariable)
{
_SpecXMLFileNameCache.Add(aFileName,false);
}
}
public void UpdateXMLFileNameStatus(string aFileName)
{
lock(LockVariable)
{
if (_SpecXMLFileNameCache.ContainsKey(aFileName))
_SpecXMLFileNameCache[aFileName] = true;
}
}
public bool ContainsXMLFileName(string aFileName)
{
lock (LockVariable)
{
bool bAlreadyObtained = false;
_SpecXMLFileNameCache.TryGetValue(aFileName, out
bAlreadyObtained);
return bAlreadyObtained;
}
}
}
....
private void btnAddSpecXMLFileName_Click(object sender,
EventArgs e)
{
if (eAddSpecXMLFileName.Text.Trim() != "")
{
aFileCache.AddXMLFileName(eAddSpecXMLFileName.Text);
}
}
}
}
The user will add items to this list via the GUI. A background thread
is running that will have an external list of files. It will see if
the file name is in the list above and hasn't yet been downloaded. If
this is the case it will download the file and update the item in the
list as downloaded.
Are there any threading issues here?
Thanks
~Gina_M~