An electric fence (1) for deterring animals (7) from an area with one or more supplies of feed (14) and at least one separate feed processing machine(12, 19), wherein the fence (1) comprises an electrically conductive member(2a, 2b, 2c, 2d, 2e), an electric power supply(6)connected to said member (2a, 2b, 2c, 2d, 2e) for energizing the member (2a, 2b, 2c, 2d, 2e) and arranged to provide an electric shock to an object coming into contact with said member(2a, 2b, 2c, 2d, 2e). A controller(18)is operatively connected to the fence(1), wherein the controller(18) is arranged to measure a value of an electrical parameter of the fence(1), and to automatically adjust the operating state of the machine (12, 19) within the area when the measured parameter value fulfils a predetermined criterion.