Yes, but you could click to smelt, then level up and you'd still have ores in your inventory but you wouldn't be smelting. The solution you posted is idiotic. The only way that would work would be to store the amount of ores you have and keep checking for a change within a certain time else smelt again, which isn't what you said.
That's horrible, why would you sleep in a method that's trying to work out if you're busy?