I have created APs programmatically, when I try to delete the AP (that is currently connected) I am getting error.. is there a way to first disconnect and then try deletion of the AP.

Below is the code for deletion

RCmManagerExt cmManager;
cmManager.OpenL();
CleanupClosePushL( cmManager );
RCmConnectionMethodExt plugin = cmManager.ConnectionMethodL(apid); // apid is the id of the AP that needs to be deleted.
CleanupClosePushL(plugin);

TUint32 destinationId( 1 ); // 1 For internet

RCmDestinationExt destination = cmManager.DestinationL( destinationId );
CleanupClosePushL( destination );
destination.DeleteConnectionMethodL(plugin);
destination.UpdateL();