The photo above shows a very worn chain riding up the teeth on the front chainwheel. That chain is obviously worn and will be responsible for odd noises and poor gear changes. So how can you tell if a chain is worn? The simplest way is to use a chain checking tool at least once a month. This will tell you if the chain has worn along it's length - often called stretch. However it is possible that a chain may pass it's "stretch" test but still be worn. How so?
I recently had a race winning bike in that was reported to have a poor gear change. When I checked the rear cassette I could see it was floating on the freehub body due to someone not fitting a required 1.85mm spacer (10 speed cassette on an 11 speed freehub). The cassette was never going to tighten on the freehub without that spacer.
I fitted the correct spacer and popped the wheel back in the bike and the gear change was as bad as before. Because the cassette had been floating on the freehub it had caused premature lateral wear in the chain. Putting a brand new chain on fixed the problem instantly. I had a similar case where the chain passed its stretch test but the bike had a poor gear change. In this case the lateral wear was likely caused by the rider's use of the gears with some hard riding.
If you've checked everything else (cables, gear hanger alignment, sprocket wear etc) a new chain might just improve your gear change.
As to the question "how long does a chain last?" - the answer is "not as long as you think"!