I have found what was causing the error to occur. My project consist of a form and a module. I call the form via the module in the manner:
form.show
I forgot to set in the properties of the project to have the program start from the module Sub Main sub-routine. After selecting this option the program work as normal when called by a schedule task.
I hope this information help anyone that runs into the same scenario.