Consider a customer X, who wishes to obtain service at a queueing system. When X arrives at this system, he has three possible courses of action to choose from, (i) join the system; (ii) not to join the system now, but return later after a random amount of time; or (iii) to leave without obtaining service. Suppose that the system has a set of forbidden states and when X, upon arrival, finds the system in one of these forbidden states, he has no choice but to return later. Otherwise, he joins the system. The problem addressed in this paper is the following: Given that every unsuccessful retrial costs a certain amount and every unit of time spent waiting outside the system costs a certain amount, then after how long a period, possibly random, should X try his luck again? The authors show that under the assumption that all forbidden states are regenerative, there are deterministic (i.e. non-random) optimal retrial times that minimize the expected cost of getting served. Several applications are discussed.