Hello David.
What DIO board are you using in this application? This information may allow us to utilize special features that the board offers to give you a more elegant solution.
The -200587 error is caused when the specified digital lines are reserved by another task. The error message recommends that if you are using the lines with another task, you will need to wait for the task to complete.
Since a random process is being used to determine what channel is to be used for the DIO operation, there will need to be some type of action if this random process causes 2 apps to attempt to access the same line. The first way to deal with this is via error handling. If you receive this error, you could simply disregard it and go back to normal operation by using the 'Clear Errors' VI. This would work, but it doesn't attempt to execute the DIO operation after the first operation completes.
Another way to resolve this is by using semaphores. Semaphores are very helpful "when you want other VIs or parts of block diagram to wait until another VI or part of a block diagram is finished with the execution of a critical section." There is a great tutorial on semaphores available at:
Using Semaphores
Let us know if you require further assistance. We will be happy to help!
Brian F
Applications Engineer
National Instruments