Make sure that the frame you are trying to dispose of exists and is running:


if (frame != null)
{
frame.dispose();
}