Serial port blocking itself?

I am trying to communicate between a C# program on a PC and an Arduino board using serial communication. Currently I'm trying to send the data as a string (I tried as bytes earlier, but I couldn't get it to work correctly), but I don't receive from the Arduino the output I expect. I littered the Arduino code with prints to see where it stops. When I just send the first string of data, I get the expected output until the part it waits for the next string, but once I add the line(s) for sending the other strings, the output I get on the PC is cut very close to the start, most of the time it won't even get past the 1st print right at the start. I tried adding some delays here and there since I found on the internet something about serial communication being much slower than the scripts, but it only helps to get the prints before the 2nd string is supposed to be received. I only get the other prints when the previous delay in the C# script is long enough for the Arduino to time out on receiving it. I guess that the problem has to do with timing of the scripts, and the serial port getting blocked by signals from both sides, or something like that, but I'm very new to this. This is my first time ever writing a program that involve 2 separated devices working together.

Here is my C# code (sorry for the messy code, I just keep on adding stuff as I experiment.):

using System.IO.Ports;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Program started");

        short[,] pinTargets = new short[8,2] {{2, 28}, {3, 26}, {4, 25}, {5, 22}, {6, 27}, {7, 24}, {8, 29}, {9, 23}};

        SerialPort port = new SerialPort();
        port.PortName = "COM6";
        port.BaudRate = 9600;
        port.Parity = Parity.None;
        port.DataBits = 8;
        port.StopBits = StopBits.One;
        port.Open();

        port.WriteLine("Begin");
        short x = (short)pinTargets.GetLength(0);
        short y = (short)pinTargets.GetLength(1);
        Console.WriteLine("X = " + x + " Y = " + y);
        //int dataSize = sizeof(int);
        //byte[] data = new byte[dataSize];
        port.Write(x.ToString());
        /* data = BitConverter.GetBytes(x);
        port.Write(data, 0, dataSize);
        Console.Write("Array length as bytes that was sent: ");
        printArr(data);*/
        //System.Threading.Thread.Sleep(10000);
        for(int i = 0;i<x;i++)
        {
            //System.Threading.Thread.Sleep(900);
            /*data = BitConverter.GetBytes(pinTargets[i,0]);
            port.Write(data, 0, dataSize);

            data = BitConverter.GetBytes(pinTargets[i,1]);
            port.Write(data, 0, dataSize);*/
            port.Write(pinTargets[i,0].ToString());
            port.Write(pinTargets[i,1].ToString());
        }
        Console.WriteLine();

        //port.WriteLine("test");
        System.Threading.Thread.Sleep(1000);
        Console.WriteLine(port.ReadExisting());
        //Console.WriteLine(port.ReadTo("Check finished"));
        port.Close();

        Console.WriteLine("Program finished");
    }

    public static void printArr(byte[] arr) 
    {
        int len = arr.Length;
        for(int i = 0;i<len;i++)
        {
            Console.Write(arr[i]);
        }
        Console.WriteLine();
    }
}

Here is my Arduino code (the program is supposed to help a user identify which end of a cable belongs to witch other end inside a mess of cables. The array being transmitted is the "correct" connections):

#include <ByteConvert.hpp>

long preMill = 0;
const long interval = 5000;
int run;
//long pinTargets[8][2] = {{2, 28}, {3, 26}, {4, 25}, {5, 22}, {6, 27}, {7, 24}, {8, 29}, {9, 23}};
int dataSize;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(22, INPUT_PULLUP);
  pinMode(23, INPUT_PULLUP);
  pinMode(24, INPUT_PULLUP);
  pinMode(25, INPUT_PULLUP);
  pinMode(26, INPUT_PULLUP);
  pinMode(27, INPUT_PULLUP);
  pinMode(28, INPUT_PULLUP);
  pinMode(29, INPUT_PULLUP);
  dataSize = sizeof(long);
}

void loop() {
  // put your main code here, to run repeatedly:
  /*long currMill = millis();
  if(currMill-preMill >= interval)
  {
    preMill = millis();*/
    if (Serial.available() > 0 && Serial.read() == 10)
    {
      Serial.println("Starting...");
      //byte data[dataSize];
      /*Serial.readBytes(data, dataSize);
      Serial.print("Arrey length as bytes that was recived: ");
      printArr(data);
      long numOpins = ByteConvert::arrayToVar<long>(data);*/
      int numOpins = Serial.parseInt();
      Serial.println("test");
      long pinTargets[numOpins][2];
      Serial.print("Recived length of array as ");
      Serial.println(numOpins);
      for(int i = 0;i<8;i++)
      {
        /*Serial.readBytes(data, dataSize);
        long convertedData = ByteConvert::arrayToVar<long>(data);
        pinTargets[i][0] = convertedData;

        Serial.readBytes(data, dataSize);
        convertedData = ByteConvert::arrayToVar<long>(data);
        pinTargets[i][1] = convertedData;*/
        pinTargets[i][0] = Serial.parseInt();
        pinTargets[i][1] = Serial.parseInt();

        Serial.print("Recived data for slot ");
        Serial.println(i);
      }
      Serial.println("Started pre-check preparations");
      for(int i = 2;i<=9;i++)
      {
        digitalWrite(i, HIGH);
      }
      Serial.println("Check started");
      //for(int i = 2;i<=9;i++)
      //int numOpins = sizeof(pinTargets)/sizeof(pinTargets[0]);
      for(int p = 0;p<numOpins;p++)
      {
        int i = pinTargets[p][0];
        digitalWrite(i, LOW);
        Serial.print("Sent signal with pin ");
        Serial.println(i);
        bool recived = false;
        for(int j = 22;j<=29;j++)
        {
          if(digitalRead(j) < 0.5)
          {
            Serial.print("Recived at ");
            Serial.print(j);
            if(pinTargets[i-2][1] != j)
            {
              Serial.print(" but was supposed to recive at ");
              Serial.print(pinTargets[i-2][1]);
            }
            Serial.println();
            recived = true;
          }
        }
        if(!recived)
          {Serial.println("No signal recived");}
        digitalWrite(i, HIGH);
      }

      /*byte x[4] = {0b10000000, 0b10000000, 0b10000000, 0b10000000};
      Serial.println(ByteConvert::arrayToVar<long>(x));*/
      Serial.println("Check finished");
    }
  //}
  
  //delay(5000);
}

void printArr(byte arr[])
{
  int len = sizeof(arr);
        for(int i = 0;i<len;i++)
        {
            Serial.print(arr[i]);
        }
        Serial.println();
}

Interesting...

Oops

The serial input basics tutorial will show more robust ways to do serial comms.

Both directions work independently.

Perhaps you should increase the baudrate for faster transmission. If your C# ports are not blocking on too fast output then you should wait before each line transmission for a prompt from the Arduino.

Making it wait for a prompt from the Arduino worked. Thanks.