Stop scanning in esp32

Hello, i want to stop scanning of ble in esp32. i got stuck i write the following program but it is not working not able to stop scanning of ble in esp32.....

if((scanTime>300)||(count_devices_found>100)) //if yes then write into file
{
Serial.println("............test...........");
advertisedDevice.getScan()->stop();
}
data_write_flag = 1;
please help thanks in advance