In general you should move from Scheduled Tasks to BackgroundTasks and Triggers. You many need to add a UWP process to your package to handle the types of Triggers you want (ie: TimeTrigger). Note that we are adding support in Windows 10 (2004) for PushNotificationTriggers from a fulltrust Win32 process, and we would like feedback on which additional triggers developers would be interested in.
For completeness, if you need to stay with a ScheduledTask, you can mitigate part of the issue when the app is running by subscribing to the PackgeUninstalling event and do clean up. If the app is not running, there is no solution.