"Best" is subjective and depends on context. One problem with either is that you can risk deadlocks if some code uses the same locks in a different order. If you have nested locks, then personally at a minimum I'd be using a lock-with-timeout (and raising an exception) - an exception is better than a deadlock. The advantage of taking out both locks immediately is that you know you can get them, before you start doing the work. The advantage of not doing that is that you reduce the time the lock on lockObject2
is held.
Personally, I would be looking for ways to make it:
lock (lockObject) {
//critical portion for lockObject
}
lock (lockObject2) {
//critical portion for lockObject2
}
This has the advantages of both, without the disadvantages of either - if you can restructure the code to do it.