Results 1 to 13 of 13

Thread: Stream unreadable

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2014
    Posts
    31

    Stream unreadable

    Ok, so I have a for loop that runs multiple threads that calls a sub each time and in this sub I make a new stream_reader, the program runs fine running on the normal thread but as soon as I make more than 1 it crashes and says "stream not readable" on line

    Read_Stream = New StreamReader(m_sslStream)

    Normally my program doesn't have a problem on the main thread, it can go through the for loop and create a new readstream everytime, but soon as I enable threads, broken.

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Stream unreadable

    can you post your code ?
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: Stream unreadable

    We'll probably have to see a larger chunk of your code to see what the problem is. Can you post it please? Please use [CODE] tags around it to keep it nice and tidy as well.
    It sounds like you might have a cross-thread access problem though.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2014
    Posts
    31

    Re: Stream unreadable

    Quote Originally Posted by Jenner View Post
    We'll probably have to see a larger chunk of your code to see what the problem is. Can you post it please? Please use [CODE] tags around it to keep it nice and tidy as well.
    It sounds like you might have a cross-thread access problem though.
    I thought this but then I thought.. it's on a new thread so it's completely different from it? so how can it be a problem?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2014
    Posts
    31

    Re: Stream unreadable

    Code:
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            
            
            For x As Integer = 1 To CInt(nudThreads.Value)
                
                Dim t As Threading.Thread = New Threading.Thread(Sub() Getinbox())
                
                t.Start()
            Next
    in my getinbox code
    Code:
    NetworkS_tream = POP3.GetStream()
            m_sslStream = New SslStream(NetworkS_tream)
            m_sslStream.AuthenticateAsClient(PopHost)
            Read_Stream = New StreamReader(m_sslStream)

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Stream unreadable

    Do we have to guess what type of object POP3 is, or can you tell us? The name only suggests what it does.

    The educated guess answer is that POP3.GetStream returns its single instance internal stream, and you are basically trying to access this same stream on multiple threads.
    Think of it like loads of different people trying to write on the same piece of paper at the same time, where should each one start to ensure that people are not destroying each others work.

  7. #7
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Stream unreadable

    A quick google shows your code to be nearly identical to this link. This shows POP3 as TCPClient, which will only give you a single stream, if you want multiple streams, you have to create multiple connections.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2014
    Posts
    31

    Re: Stream unreadable

    Quote Originally Posted by Grimfort View Post
    A quick google shows your code to be nearly identical to this link. This shows POP3 as TCPClient, which will only give you a single stream, if you want multiple streams, you have to create multiple connections.
    Yep you are right..

    Dim POP3 As New TcpClient is already in my loop though, so it's creating a new one everytime right? no?
    Last edited by x34cha; Oct 15th, 2014 at 09:58 AM.

  9. #9
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Stream unreadable

    I would think No. You have only one reference, POP3, so it can only reference one object at a time. If you set POP3 to reference a new TcpClient in a loop, you lost your reference to the previous TcpClient it reference.
    Normally if you want multiple TcpClients you have to have multiple variables to hold references to the object, or more likely use an array or some sort of collection/list to hold the references to the objects.
    I would thing the same would be true for your threads. Using the same t variable to hold the reference temporarily to each thread as you start it up, then "toss" it, is not something I would have tried, but perhaps you can "orphan" a thread and it will continue without your program having a reference to it, but it strikes me as being unnatural.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Oct 2014
    Posts
    31

    Re: Stream unreadable

    Ok, I will try using an array to hold them, thanks.

  11. #11
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: Stream unreadable

    I would think that having orphaned threads would lead to a memory leak or premature thread termination or some other sort of undesirable outcome.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Oct 2014
    Posts
    31

    Re: Stream unreadable

    Quote Originally Posted by dolot View Post
    I would think that having orphaned threads would lead to a memory leak or premature thread termination or some other sort of undesirable outcome.

    One step at a time xD

  13. #13
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    Re: Stream unreadable

    I understand.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width