The plaintiff shall have the right to take a voluntary nonsuit or to dismiss an action without prejudice at any time before the cause is finally submitted to the court, but not afterwards; provided, that such a dismissal operates as an adjudication upon the merits when filed by a plaintiff who has twice dismissed in any court an action based on or including the same claim.