Session in scripts

Hi Experts

I have to process thousands of Person objects, and run a certain set of functions for each Person. I can iterate over each person in a For Loop and do it synchronously, but I though I'll try doing it Async and process in parallel

When I did this, it works for a while (i.e. some objects do get processed successfully and in parallel), but then I get an error from the script which is executing the function asynchornously (using await and tasks in vb.net). The function itself is inserting new entries into a custom table for each user

Error are

The session is already disposed.

and

Trying to execute SQL in canceled transaction

It seems as if the process which runs the script finishes after executing the script, and in doing so the session is terminated.
Is it possible to query if a session is terminated within a script, and if so, instantiate a new session? I think if I can create a Session object manually and pass it as a parameter to all the tasks then I should be able to avoid the issue

Thanks

PS: Using 1IM v8.0