Deadlocks usually happen when 2 processes are vying for control of 2 of the same objects, EG:
Process 1 acesses object A, and holds it whilst trying to access object B.
In the meantime process 2 acesses object B and holds it whilst trying to access object A.
This means that both of them are waiting for access to an object that the other is holding and a deadlock occurs.
The best way around this is to make sure that both of the processes access the objects in the same order, so in this case either process 1 and 2 try to access first A then B, or process 1 and 2 try to access B then A.
Other possible options are to avoid user interaction in these processes, keep any transactions short & try to keep as low an isolation level for transactions as possible.