We have two projects which are using the same database.
As one of the projects undergoes an heavy database operation, the other may do small Task
requests like these:
public async Task<ActionResult> GetManaIconAsync(string _mana)
{
string mana = _mana.Replace("/", "");
byte[] imageData = await Task.Run<byte[]>(() => mImateManager.GetManaByName(mana));
return File(imageData, "image/png");
}
public byte[] GetManaByName(string _mana)
{
using (MyDb db = new MyDb())
{
db.Database.Connection.Open();
IQueryable<ITEM_IMAGES> imageQry = from img in db.ITEM_IMAGES
where img.ITEM_IMAGE_TYPE == (int)ImageTypes.Mana
select img;
if (!imageQry.Any())
{
return null;
}
return imageQry.First(_item => _item.ITEM_NAME == _mana).ITEM_IMAGE;
}
}
And project2 would crash when hitting the if(!imageQry.AnY())
saying that the wait operation timed out, which is normal since project1 is currently doing heavy work.
Now my question is how could I solve this? What are the options available so that both may do their respective work without impacting (too much) the other?