The latch itself may not be malfunctioning; there may be something in the way of the door. The latch spring may have been compromised, or the control panel may be broken, depending on the type of latch.
You'll have to tighten any screws that may be loose, or adjust any cabinetry that could be getting in the way of the door. If the latch's spring is broken, it may need replacing or cleaning. A new control panel may be necessary if the latch doesn't work and the dishwasher won't come on.
Keep the perimeter of the door clear of objects, and keep it clean so that it shuts properly. Always make sure the door is completely closed before starting the wash cycle, and don't open the door mid-cycle.