Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. StreamReader.readline() problem

StreamReader.readline() problem

Scheduled Pinned Locked Moved C#
helptutorialquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Admin887
    wrote on last edited by
    #1

    hi, i have a program that receiving inforamtion from a port (SerialPort object). i am reading the port's information(Stream) from another object by StreamReader like this:

    SerialPort port=new SerialPort(.....);
    port.NewLine= "\r";
    StreamReader sr=new StreamReader(port.BaseStream);

    while reading the the stream to the end:

    while (!sr.endOfFile)
    {
    line= sr.readLine();
    }

    this Method stucks on the last line on the stream.it reads all the Stream except the last line. But after adding information (Strings) to the stream (from the port).. it continues reading the last line with the new information... do you know how to solve it? thank you.. P.S Maybe..is it something with the sr.NewLine argument?

    D P 2 Replies Last reply
    0
    • A Admin887

      hi, i have a program that receiving inforamtion from a port (SerialPort object). i am reading the port's information(Stream) from another object by StreamReader like this:

      SerialPort port=new SerialPort(.....);
      port.NewLine= "\r";
      StreamReader sr=new StreamReader(port.BaseStream);

      while reading the the stream to the end:

      while (!sr.endOfFile)
      {
      line= sr.readLine();
      }

      this Method stucks on the last line on the stream.it reads all the Stream except the last line. But after adding information (Strings) to the stream (from the port).. it continues reading the last line with the new information... do you know how to solve it? thank you.. P.S Maybe..is it something with the sr.NewLine argument?

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Try sr.ReadLine != null in while loop condition.

      जय हिंद

      A 1 Reply Last reply
      0
      • D dan sh

        Try sr.ReadLine != null in while loop condition.

        जय हिंद

        A Offline
        A Offline
        Admin887
        wrote on last edited by
        #3

        it stucks on readLine. i mean, the processor arrives to this line (line= sr.readline()) and just stop. even if i add another line to while:

        while(!sr.endOffile)
        {
        line= sr.readline(); <------------it stops here------
        messageBox.show("Just string"); the processor do not arrive to this line

        }

        the processor stops working even if the Stream is not endOfFile. Why?! P.S i changed !sr.endofFile to line!=null it is still not working...

        1 Reply Last reply
        0
        • A Admin887

          hi, i have a program that receiving inforamtion from a port (SerialPort object). i am reading the port's information(Stream) from another object by StreamReader like this:

          SerialPort port=new SerialPort(.....);
          port.NewLine= "\r";
          StreamReader sr=new StreamReader(port.BaseStream);

          while reading the the stream to the end:

          while (!sr.endOfFile)
          {
          line= sr.readLine();
          }

          this Method stucks on the last line on the stream.it reads all the Stream except the last line. But after adding information (Strings) to the stream (from the port).. it continues reading the last line with the new information... do you know how to solve it? thank you.. P.S Maybe..is it something with the sr.NewLine argument?

          P Online
          P Online
          PIEBALDconsult
          wrote on last edited by
          #4

          ReadLine doesn't terminate until it encounters a NewLine; try a different method.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups