Course crash in simple thread?

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 .

- . , !

+3
3

TPL, Parallel Task.

, , . . , . CPU ( , ..), .

TPL, , :

    Call Parallel.Invoke(
        Sub()
            Me.ParseFirstString(SomeStrArr(0))
        End Sub,
        Sub()
            Me.ParseFirstString(SomeStrArr(1))
        End Sub)

, VB.NET. , .

+2

Threading ( ) , , // .

, , .

- ..NET 4 "". - , . .NET Framework ( , , ), .

, , . , - , , . , , .

+2

, , . , - , , , , .

, . , / .

.net - #, .

, , , , .Invoke

, , , , , , , , , . -, ", ", , .

, , , (, ) 10 000 .

In appearance, you have a better idea, take the code you want and then try each of the methods, see which one is right for you, your way of thinking and speed. If you find that one of them is much slower than any other, or the user interface thread that runs it is likely there is a way to improve it.

MS, of course, has many examples for each view so you can get started if you are stuck with examples.

0
source

All Articles