Ich war gerade dabei(,) die Tür abzuschliessen(,) wenn/dann/als du anriefst.
I was about to close the door,
when/then/as you called me.
This simple translation should give you an idea: the first two are incorrect, but the last one fits.
"wenn" could be right in the future, but "war" and "anriefst" are in the past, so "wenn" doesn't work here, because wenn is conditional and not time-related. And as it gappened in the past you can't say you're going to close the door, when you call. "wenn" can also be translated as "while" but also this doesn't work here as it happened in the past and in the past you juse "als" in germany.
Also the first comma is optional and the second one shouldn't be used. I'd recommend to use the first one as it looks better. Don't ask me why, but it does. However I know you can skip it. The second one (you used) is not necessary, but you can use it too.