multithreading - VB.NET RaiseEvent in thread -
When I increase an incident in my thread, the thread is no longer running in the loop. NetworkTream = Me.client.GetStream () byte () = New byte (20000) {} Try slowing down as netstream as a net substrate. {} Netstream.Read (inStream, 0, CInt ()) Console.WriteLine ("Some Received") RaiseEvent rsh (I, New ReceiveStreamEvent (System.Text.Encoding.ASCII.GetString (inStream)) Console .WriteLine ("I'm still alive") Exception Console ("ReadStream Error:" and formerly. Message: Toastring ()) and Trude Thread. Sleep (100) Loop and all
You can see that "I'm still alive" never happens .. I did the same code in C #, I have with it This is not an issue, so when the RaiseEvent is called, the thread will not continue. I have no errors, no messages.
Here's the full square:
Import system. Selection. GENERAL IMPORT SYSTEM Link Import Systems Text import system met. Sockets Import Systems Public Delayat All Receive StrielHandler (Receive Object, Source, E-Receive Event) as source, Receive Public ClassStream Event Inventions EventRGS Private Stream String Public Sub New (stream as String) me.stream = stream end sub public function getstream () string Me.stream end function as the return termination class folk class server private client TcpClient personalized thread as thread. Generic Event RSH ReceiveStreamHandler Public Sub New () Me.client = Try New TcpClient ("172.16.26.56", 8000) Me.readThread = As New Thread (AddressOf readStream) Me.readThread.Start () Me Try the End End Public Sub Disconnect (try) end. Try to end .readThread.Priority = ThreadPriority.Highest pre-exceptions as Console.WriteLine ("TCP Conn error:" & amp; ex.Message.ToString ()) Interesting Catch Me.client.Close () as pre-Eption Console.WriteLine ("TCP Disk Error:" & amp; ex.Message.ToString ()) End End Sub Public Sub ReadStream () as Due Netstream Try NetworkStream = Me.client.GetStream () Try Dim InStream as Byte () = New byte (20000) {} netStream.Read (Instream, 0, CINT (Mayclient resavebuffer size)) Console.rightline ("received something") RieSevent RSH (m, new receivstream event (system text encoding.a SisiItGreatString (Instream)) Console Catch up as a capsule console. Wrightite ("ReadStream Error:" and formerly .tostring ()) and Threat 'Thread.Sleep (100) Loop and Sub Public Substream (form of message string NetStream.Write (outstream, 0, outStream.Length) by using NetStream.Flush as NetStream NetworkStream = Me.client.GetStream () as in byte () = System.Text.Encoding.ASCII.GetBytes (message) (Slow outstream) End Sub ending class
This is more than one answer But the code below shows that my sub event was used when using the console.WrititeLine () on E.getstream. This once showed a result, the rest of the code was never and neither did I thread it. It has been added to the comment, and now everything works correctly. Even if I use E.getstream () it works like this is a situation that actually made me crazy by VB.Net Give and even if C # Tho Hi be "similar" it is clearer and more intelligible. I still do not have any answer for this consumer console. Write and be glad if some of the friends here can think about this. Because it is very unclear wakadudle thing here.
Private sub receiveData (as the source object, in the form of e ReceiveStreamEvent) handle apiServer.rsh 'Me.richTextBox_DATA.Invoke (Try New MethodInvoker (sub) my .richTextBox_DATA.Text = Me.richTextBox_DATA.Text + e.getStream ())) 'Console.WriteLine (e.getStream ()) as dim list string () = e.getStream (). Split (new string) {vbLf, VbCr and vbLf}, string split option. RemoveEmptyEntries) str.tartsWith ("RESP") in the string list for each string then end the Me.parseResp (str) if str.StartsWith ( "LOGOUT") then Me.parseLogout (Str) end if if str. With ("log in") then Me.parseLogin (str) end if if str. Together ("GPS") then the console Wrightite ("GPSGPS") ends up in the form of the next catch-up exception console. WriteLine (Ex.Message) Try End End
Comments
Post a Comment