InvokeRepeating not stopping after object set to inactive. Any workaround ?

When Object A spawns Object B, after 1 second, Object B spawns Object C using InvokeRepeating. I have my InvokeRepeating code on Object B, so that whenever Object B becomes active, it spawns Object C. When Object B touches an enemy object, it becomes deactivated, but it still continues to spawn Object C even after being deactivated. A few seconds later, Object A spawns Object B again, but InvokeRepeating is running already and doesn’t spawn Object C at the correct time. If I make it so, that when Object B touches an enemy object, it should CancelInvoke the InvokeRepeating code, then InvokeRepeating never gets called again ever. Are there any workarounds to this ? Here is my code:

void Start () {
		InvokeRepeating("Spawn", spawnDelay, spawnTime);
missiles = new List<GameObject> ();
		for (int i = 0; i < pooledAmount; i ++) 
		{
			GameObject obj = (GameObject)Instantiate(missile);		
			obj.SetActive(false);
			missiles.Add (obj);
		}
void Spawn ()
	{
		for(int i = 0; i < missiles.Count; i++)
		{
			if (!missiles*.activeInHierarchy)*
  •  	{*
    

_ missiles*.transform.position = transform.position;_
_ //missiles.transform.rotation = transform.rotation;
missiles.SetActive(true);
break;
}
}
}*_

How about using a coroutine ?

void OnEnable() {
	StartCoroutine(Spawn());
}

IEnumerator Spawn() {
	yield return new WaitForSeconds(spawnDelay);

	while(true) {

		// Your code

		yield return new WaitForSeconds(spawnTime);
	}
}

coroutine is best if u want stop ur thread at any time .InvokeRepeating repeating thread is continue untill its max limit.