How is motivation influenced by chance of reward? Sometimes, I work on a project where there is a chance that the whole project will become irrelevant before it is finished. I have noticed that even though I believe that the risk of this happening is small, it will significantly influence my motivation sometimes, though not on every project where there is such risk. On the other hand, when gambling, one is willing to do things, when the chance of reward is practically neglectable.

Are there any psychological experiments that can shed some light on why we react irrationally in these situations?
Our subjective estimation of probability is affected by many irrational factors, one of which is the accessibility of exemplars (Availability Heuristic). Since we usually hear about lottery winners, and not so much about those who didn't win, we over-estimate the probability of winning. It may be similar with your estimation of the probability of the project becoming irrelevant - it is affected by how easy it is for you to imagine the project failing, something that can be affected by lots of irrational factors (like how self-confident the project leader is, or even worse, how much you like him/her).

Dan Gilbert has a nice TED talk mentioning the Availability Heuristic in lottery and other similar biases in estimating gains and probabilities.