I'm testing the idea of threads, but only at the most key points right now. Themes add a rather fascinating level of sophistication to pretty much everything, but with .NET it seems like there are many options for streaming in System.Threading. I am looking to find out what is best for passing string operations.
Consider the string complex , which is fed to the user object. This object is currently dividing the string at some point and passing part of the first function, and then, when this function is completed, passing the second half of the string to the second function. These two functions are not dependent on each other, so they should be good candidates for streaming so that both functions can work simultaneously on each fragment of the line.
Example before registration:
Public Sub ParseString(ByVal SomeStr As String)
If String.IsNullOrWhitespace(SomeStr) Then
Throw New ArgumentNullException("SomeStr")
End If
' Assume that ParsedFirstString is a boolean that is set to
' True if the call to ParseFirstString completes successfully.
' Ditto for ParsedSecondString.
Dim MyDelimiter As Char = "|"c
Dim SomeStrArr As String() = SomeStr.Split({MyDelimiter}, 2)
Call Me.ParseFirstString(SomeStrArr(0))
If Me.ParsedFirstString = False Then
Throw New ArgumentException("Failed to parse the first part of the string.")
End If
Call Me.ParseSecondString(SomeStrArr(1))
If Me.ParsedSecondString = False Then
Throw New ArgumentException("Failed to parse the second part of the string.")
End If
End Sub
, 1000 ~ 140 -170 (avg ~ 1200 +, 10 000 ). , , . , SO , :
Public Sub ParseString(ByVal SomeStr As String)
If String.IsNullOrWhitespace(SomeStr) Then
Throw New ArgumentNullException("SomeStr")
End If
Dim MyDelimiter As Char = "|"c
Dim SomeStrArr As String() = SomeStr.Split({MyDelimiter}, 2)
Dim FirstThread As New Thread(Sub() Me.ParseFirstString(SomeStrArr(0))
Dim SecondThread As New Thread(Sub() Me.ParseSecondString(SomeStrArr(1))
FirstThread.Priority = ThreadPriority.Highest
SecondThread.Priority = ThreadPriority.Highest
Call FirstThread.Start()
Call SecondThread.Start()
If Me.ParsedFirstString = False Then
Throw New ArgumentException("Failed to parse the first part of the string.")
End If
If Me.ParsedSecondString = False Then
Throw New ArgumentException("Failed to parse the second part of the string.")
End IF
End Sub
, , , . , Join, . , . 1000 , ~ 3700 . , .
, , , ThreadPools BackgroundWorkers. , , ( ).
? ?
FYI, - .
:
:
, , . Parallel Class , 10000 , , ~ 1220 -1260 . Parallel.Invoke(), , ~ 300 (, - , , ). Core2 Q9550 Yorkfield, 95 .
- . , !