当前位置: 代码迷 >> 多核软件开发 >> 多线程同步求教大家,多谢!
  详细解决方案

多线程同步求教大家,多谢!

热度:2280   发布时间:2013-02-26 00:00:00.0
多线程同步求教大家,谢谢!!! - .NET技术 / VB.NET
每个线程调用同一个类模块执行一个计算(我的代码执行时不能正确执行),请大家帮助,谢谢!!!


VB.NET code
 Public Class 趋势图Private Sub sdnd()        Dim VV As New XTHTHS        Call VV.TYZHDY(UCase(ISTRNN(istr, Threadnew)), Threadnew)    End Sub    Private Function ISTRNN(ByVal NSTRW As String, ByVal ISH As Short) As String        Dim w1 As Integer, w2 As Integer        Dim tmp As String        tmp = "{" & ZBGH(ISH) & "}" & vbCrLf        w1 = InStr(UCase(NSTRW), tmp) : w2 = InStr(w1, UCase(NSTRW), "ABCDEFGHIJKLMNOPQRSTUVWSYZ{}[]")        ISTRNN = Mid(UCase(NSTRW), w1 + Len(tmp), w2 - w1 - Len(tmp) - 1)    End Function    Public Sub drawlozt()        Dim adsa As DateTime = Now        hqs.start = IIf(MaxSize > EveryScreenDay, MaxSize - EveryScreenDay, 0) '保证每屏显示EveryScreenDay天数据        If hqs.start + EveryScreenDay > UBound(hq) Then            hqs.endd = UBound(hq)        Else            hqs.endd = hqs.start + EveryScreenDay        End If        If GetMaxValue(hqs) Then            PDTIANSHU = True            Tabbmp = New Bitmap(Pichqk.Width, Pichqk.Height)            GTabbmp = Graphics.FromImage(Tabbmp)            Kbim = Tabbmp.Clone            GKbim = Graphics.FromImage(Kbim)            If hzzb1 = True Then                If hdzb = True Then                    Dim a As Threading.Thread                    PDXCJS = True  '全局变量                    For ii As Short = 1 To 5                        Threadnew = ii - 1                        a = New Threading.Thread(AddressOf Me.sdnd)                        a.Name = ii                        a.Start()  每个线程调用同一个类模块执行一个计算(我的代码执行时不能正确执行)                        '我想当在PDXCJS = False时执行下一个线程                     Next                 End If         End IfEnd SubEND CLASSPublic Class XTHTHS'.....'.....PDXCJS = False  '全局变量 传递给“趋势图”执行下一个线程END CLASS


------解决方案--------------------------------------------------------
你在线程里加个循环不行吗?
把这个(For ii As Short = 1 To 5)循环放到线程函数里,根据
PDXCJS变量值来执行下一个循环

------解决方案--------------------------------------------------------
'调用线程那个for循环去掉
VB.NET code
Private Sub sdnd()        Dim VV As New XTHTHS        VV.PDXCJS =false        dim ii as integer=0        while(not VV.PDXCJS andalso ii<6)           Call VV.TYZHDY(UCase(ISTRNN(istr, Threadnew)), Threadnew) '这个函数里面你一开始把PDXCJS 变量置为true,执行完再置为false           ii=ii+1        end while    End Sub
  相关解决方案