DapperContext
DapperContext copied to clipboard
endless loop exception from dispose method
Hi When call the below function it goes endless loop.
May i know what did i wrong on this.
Thanks, Shiva
try
{
DboCampaign _DboCampaign;
using (var context = CreatePartnerContext())
{
using (var scope = context.CreateUnitOfWork())
{
var p = new DynamicParameters();
p.Add("@CampaignID", sqtAffID);
_DboCampaign=
context.Query<DboCampaign>("dbo.GetAccountID", p, commandType: CommandType.StoredProcedure).FirstOrDefault();
}
}
using (var context = CreateContext())
{
using (var scope = context.CreateUnitOfWork())
{
var p = new DynamicParameters();
p.Add("@RegistrationCode", _RegistrationRegistration.RegistrationCode);
p.Add("@Email", _RegistrationRegistration.Email);
p.Add("@Confirmed", _RegistrationRegistration.Confirmed);
p.Add("@ConfirmedOn", _RegistrationRegistration.ConfirmedOn);
p.Add("@ConfirmedIPAddress", _RegistrationRegistration.ConfirmedIPAddress);
p.Add("@Password", _RegistrationRegistration.Password);
p.Add("@CampaignId", _DboCampaign.CampaignID);
p.Add("@PartnerAccountID", _DboCampaign.AccountID);
p.Add("@timezonebyIP", _RegistrationRegistration.timezonebyIP);
p.Add("@AccountID", null, dbType: DbType.Int64, direction: ParameterDirection.Output);
context.Execute("[Registration].[RegistrationConfirmRegistration]", p, commandType: CommandType.StoredProcedure);
scope.SaveChanges();
_accountid=p.Get<Int64>("@AccountID");
}
}
using (var context = CreatePartnerContext())
{
using (var scope = context.CreateUnitOfWork())
{
var p = new DynamicParameters();
p.Add("@AffiliateID", _DboCampaign.AccountID);
p.Add("@CampaignID", _DboCampaign.CampaignID);
p.Add("@SquareTakeoffAccountID", _accountid);
p.Add("@licensecount", 0);
p.Add("@perlicensecost", 0);
p.Add("@Action", "Registered");
int i = context.Execute("dbo.INSERTTRANDETAILFROMPRODDB", p, 30, commandType: CommandType.StoredProcedure);
scope.SaveChanges();
if (i > 0)
return _accountid;
}
}
return _accountid;
}
catch (Exception ex)
{
SquareTakeoff.Logging.ILogService logService = new SquareTakeoff.Logging.FileLogService(typeof(RegistrationRegistration));
logService.Error(ex.Message);
logService.Error(ex.StackTrace);
if (ex.InnerException != null)
{
logService.Error(ex.InnerException.Message);
}
return _accountid;
}
public void Dispose()
{
//Use an upgradeable lock, because when we dispose a unit of work,
//one of the removal methods will be called (which enters a write lock)
_rwLock.EnterUpgradeableReadLock();
try
{
while (_workItems.Any())
{
var workItem = _workItems.First;
workItem.Value.Dispose(); //rollback, will remove the item from the LinkedList because it calls either RemoveTransaction or RemoveTransactionAndCloseConnection
}
}
finally
{
_rwLock.ExitUpgradeableReadLock();
}
if (_connection != null)
{
_connection.Dispose();
_connection = null;
}
}