[verb (dictionary form)] + か + [verb ない-form] + かのうちに [verb た-form] + か + [verb ない-form] + かのうちに
か~ないかのうちに says the second event came so fast that the first had barely happened: "hardly had… when", "the instant". The same verb appears twice – the dictionary form with か, then the ない-form with か – and のうちに follows.
The first verb can also be in the た-form: はなし話しおわった終わったかおわらない終わらないかのうちに. Either way, the second verb is the ない-form of the same verb, not a different one.
The pattern reports two events as facts, so the second clause states what happened, or what always happens. It can't be a request, an order or something you intend to do.
The pattern is a little formal and turns up mostly in written narrative. In conversation you would say たとたん or てすぐ.