An implantable medical device comprising: a magnetic field sensor; and a controller that selects between a normal mode of operation and an exposure mode of operation, the controller being configured to: while in the normal mode of operation, periodically detect whether the magnetic field sensor is producing a first signal level that suggests a magnetic disturbance is present; once the magnetic field sensor produces the first signal level while in the normal mode of operation, start an entry test cycle by setting a hysteresis timer to a hysteresis start value and adjusting a confirmation counter by a unit from a confirmation start value toward a target value; continue the entry test cycle by periodically detecting whether the magnetic field sensor produces the first signal level; when it is detected during the entry test cycle that the magnetic field sensor is producing the first signal level, set the hysteresis timer to the hysteresis start value and adjust the confirmation counter by the unit toward the target value; when it is detected during the entry test cycle that the magnetic field sensor is not producing the first signal level, adjust the hysteresis timer by the unit toward the stop value and adjust the confirmation counter by the unit toward the target value; when the hysteresis timer reaches the stop value during the entry test cycle, set the confirmation counter back to the confirmation start value; and when the confirmation counter reaches the target value during the entry test cycle, switch to the exposure mode of operation. a magnetic field sensor; and a controller that selects between a normal mode of operation and an exposure mode of operation, the controller being configured to: while in the normal mode of operation, periodically detect whether the magnetic field sensor is producing a first signal level that suggests a magnetic disturbance is present; once the magnetic field sensor produces the first signal level while in the normal mode of operation, start an entry test cycle by setting a hysteresis timer to a hysteresis start value and adjusting a confirmation counter by a unit from a confirmation start value toward a target value; continue the entry test cycle by periodically detecting whether the magnetic field sensor produces the first signal level; when it is detected during the entry test cycle that the magnetic field sensor is producing the first signal level, set the hysteresis timer to the hysteresis start value and adjust the confirmation counter by the unit toward the target value; when it is detected during the entry test cycle that the magnetic field sensor is not producing the first signal level, adjust the hysteresis timer by the unit toward the stop value and adjust the confirmation counter by the unit toward the target value; when the hysteresis timer reaches the stop value during the entry test cycle, set the confirmation counter back to the confirmation start value; and when the confirmation counter reaches the target value during the entry test cycle, switch to the exposure mode of operation. while in the normal mode of operation, periodically detect whether the magnetic field sensor is producing a first signal level that suggests a magnetic disturbance is present; once the magnetic field sensor produces the first signal level while in the normal mode of operation, start an entry test cycle by setting a hysteresis timer to a hysteresis start value and adjusting a confirmation counter by a unit from a confirmation start value toward a target value; continue the entry test cycle by periodically detecting whether the magnetic field sensor produces the first signal level; when it is detected during the entry test cycle that the magnetic field sensor is producing the first signal level, set the hysteresis timer to the hysteresis start value and adjust the confirmation counter by the unit toward the target value; when it is detected during the entry test cycle that the magnetic field sensor is not producing the first signal level, adjust the hysteresis timer by the unit toward the stop value and adjust the confirmation counter by the unit toward the target value; when the hysteresis timer reaches the stop value during the entry test cycle, set the confirmation counter back to the confirmation start value; and when the confirmation counter reaches the target value during the entry test cycle, switch to the exposure mode of operation.