private bool removePrevSocketIfPresent(Hashtable hashTableUnits, long unitID)
{
bool allWEll = false;
SocketAsyncEventArgs tempSocketToremove;
DataHoldingUserToken tempTokenToRemove;
//locking the hashtable for the whole operation
lock (TRInitModule.hashTableUnits.SyncRoot)
{
bool markForRemoval = false;
foreach (DictionaryEntry entry in TRInitModule.hashTableUnits)
{
Int64 currentUnitID = Convert.ToInt64(entry.Key);
if (currentUnitID == unitID)
{
try
{
tempSocketToremove = (SocketAsyncEventArgs)(entry.Value);
tempTokenToRemove = (DataHoldingUserToken)tempSocketToremove.UserToken;
tempSocketToremove.SocketError = SocketError.OperationAborted;
tempSocketToremove.AcceptSocket.Shutdown(SocketShutdown.Both);
//is the above line enough or do I need to do the below lines too?
// tempSocketToremove.AcceptSocket.Close();
// tempTokenToRemove.Reset();
//if (tempTokenToRemove.theDataHolder.dataMessageReceived != null)
//{
// tempTokenToRemove.CreateNewDataHolder();
//}
markForRemoval = true;
Console.WriteLine();
Console.WriteLine("One socket removed, count is = " + TRInitModule.hashTableUnits.Keys.Count);
allWEll = true;
}
catch (Exception eRT)
{
allWEll = false;
Console.WriteLine("ERROR IN REMOVE ITEM " + eRT.Message);
}
}
else
{
markForRemoval = false;
}
}
if (markForRemoval)
{
TRInitModule.hashTableUnits.Remove(unitID);
}
}
return allWEll;
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE