I have a programming scenario that I am currently looking into. I would like to remove items at the same time perform some special functions behind the scene that, in this case, will update an external database.
I thought about using an IDisposable but that would perform the deletion during shutdown of the program. If this is correct, is there some way to perform a clean-up operation only when I remove an item from a list, not during a program shutdown.
Thanks.
EDIT:
Per the comments, here is some example code:
public class CItem
{
private string Name;
private int Data;
public void destroy()
{
// Do something that performs clean up only during run-time, not program exiting
}
}
public class CMain
{
private List<CItem> items;
public setItem(CItem newItem)
{
items.add(newItem);
}
public removeFirstItem()
{
items.remove(items[0]); // remove the first item and dispose
}
}
The line items.remove(items[0]), is it possible that when an item is removed and destroyed, can I perform a back ground disposal that is only limited to the disposal during run-time?