How to Create a Task a programmatically

Hi all, I want to create a task by code, is it possible? My scenario is this: I create a document, after creating a document a task created, after complete the task the document is go for survey and this activity is done by other user2, if user2 attach new file to that document then the generation of document get changed, but now when user2 try to complete his task, then Error occured that "Not a single item", because of two generation, so is it possible to delete a task from In MyBasket which has generation 1, and create a new task to user2 of generation 2.   Regards, Maddy.