Had to google to find out the basics about P and R waves but the University of Nottingham had some information on cardiology.... including all the peaks and troughs in an ECG (P-wave, QRS sequence and T wave)
The P Wave - Sinus Rhythm - Normal Function of the Heart - Cardiology Teaching Package - Practice Learning - Division of Nursing - The University of Nottingham
From a mathematical perspective, it's just a graph with some peaks (maxima) at P and R.
From a programming perspective, if you've got this graph represented as data, you're looking for an algorithm that detects local minima and maxima (well, maxima if you want the time from P to R), or something that calculates gradient of the graph between data points, looking for a switch from positive gradient to negative (i.e. going over a peak and starting back down the other side.)
Okay - this isn't a solution per-se as I don't have an actual code to give in this instance, but Googling / Stack Overflowing for something on "c# gradient of graph" or "c# detect minima and maxima" might get you going.
Best of luck!