You can leave Canada and apply immediately. However, you will need to report where you have lived and what you were doing in the last 10 years. IRCC will very quickly find out that you were illegally in Canada and this will be a problem for you. Perhaps @scylla can provide more insights on this...