---
title: finishTasksAndInvalidate()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/urlsession/finishtasksandinvalidate()
---

# finishTasksAndInvalidate()

Invalidates the session, allowing any outstanding tasks to finish.

## Declaration

```swift
func finishTasksAndInvalidate()
```

## Discussion

Discussion This method returns immediately without waiting for tasks to finish. Once a session is invalidated, new tasks cannot be created in the session, but existing tasks continue until completion. After the last task finishes and the session makes the last delegate call related to those tasks, the session calls the urlSession(_:didBecomeInvalidWithError:) method on its delegate, then breaks references to the delegate and callback objects. After invalidation, session objects cannot be reused. To cancel all outstanding tasks, call invalidateAndCancel() instead. important: Calling this method on the session returned by the shared method has no effect.

## See Also

### Managing the session

- [flush(completionHandler:)](foundation/urlsession/flush(completionhandler:).md)
- [getTasksWithCompletionHandler(_:)](foundation/urlsession/gettaskswithcompletionhandler(_:).md)
- [getAllTasks(completionHandler:)](foundation/urlsession/getalltasks(completionhandler:).md)
- [invalidateAndCancel()](foundation/urlsession/invalidateandcancel().md)
- [reset(completionHandler:)](foundation/urlsession/reset(completionhandler:).md)
- [sessionDescription](foundation/urlsession/sessiondescription.md)
