M
Matias Woloski
I have the following code which is running in every Page_Load of my ASP.Net
app.
It basically will add rows to a table upto MAX_CACHED_ITEMS and then will
flush all the cached items to the database.
Do you foresee any concurrency problem? or any performance problem?
private object lockObject = new object();
private static DataTable myTable; //typed table
private const int MAX_CACHED_ITEMS = 50;
lock(lockObject)
{
if( myTable == null )
{
myTable = MyDal.CreateDataTable();
}
myTable.AddxxxxRow( param1, param2, param3 );
if( myTable.Rows.Count >= MAX_CACHED_ITEMS )
{
try
{
MyDal.MyTable.Update( myTable ); // update the db
MAX_CACHED_ITEMS rows
myTable.Rows.Clear();
}
catch( Exception ex )
{
//handle
}
}
}
Thanks,
Matias
app.
It basically will add rows to a table upto MAX_CACHED_ITEMS and then will
flush all the cached items to the database.
Do you foresee any concurrency problem? or any performance problem?
private object lockObject = new object();
private static DataTable myTable; //typed table
private const int MAX_CACHED_ITEMS = 50;
lock(lockObject)
{
if( myTable == null )
{
myTable = MyDal.CreateDataTable();
}
myTable.AddxxxxRow( param1, param2, param3 );
if( myTable.Rows.Count >= MAX_CACHED_ITEMS )
{
try
{
MyDal.MyTable.Update( myTable ); // update the db
MAX_CACHED_ITEMS rows
myTable.Rows.Clear();
}
catch( Exception ex )
{
//handle
}
}
}
Thanks,
Matias