We would need a bit more details on what you want to achieve, what you have and what exactly does not work please.
CMS version you have would be helpful as well.
Yes, you can use TaskTrait in your custom task, in fact, you most likely want to use it .
If you look at the example here - Tasks - Extend Xibo | Xibo Open Source Digital Signage
You need to create the .task file as explained in the link.
Then create the task file itself, which if we follow the example from docs, at the very least needs this as base
class CustomTask implements TaskInterface
public function run()
// TODO: Implement run() method.
public function setFactories($container)
// TODO: Implement setFactories() method.
You can have a look at one of the existing tasks to see how the workflow should work.
Once you’re happy you can go to Task page in your CMS, click add Task and select your custom task from the dropdown, specify cron schedule and options if needed.