Changeset 28691

Show
Ignore:
Timestamp:
01/20/09 13:09:18 (4 years ago)
Author:
kiri_feather
Message:

アイコン取得を別スレッド化(お行儀悪い)

Location:
lang/vb2005/Tween/Tween
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/vb2005/Tween/Tween/Tween.vb

    r28688 r28691  
    21592159        Me.ResumeLayout(False) 
    21602160        Me.PerformLayout() 
    2161         Diagnostics.Debug.WriteLine("inz") 
    21622161        Return True 
    21632162    End Function 
  • lang/vb2005/Tween/Tween/Twitter.vb

    r28659 r28691  
    2828 
    2929Partial Public Class Twitter 
     30    Delegate Sub GetIconImageDelegate(ByVal post As PostClass, ByVal imgs As Dictionary(Of String, Image), ByVal imgsS As ImageList) 
     31    Private iconLock As New Object 
     32 
    3033    Public links As New List(Of Long) 
    3134 
     
    279282        Dim intCnt As Integer = 0 
    280283        Dim listCnt As Integer = links.Count 
     284        Dim dlgt(20) As GetIconImageDelegate 
     285        Dim ar(20) As IAsyncResult 
     286        Dim arIdx As Integer = -1 
    281287 
    282288        For Each strPost As String In posts 
     
    525531                    End If 
    526532 
    527                     post.ImageIndex = GetIconImage(post.ImageUrl, imgs, imgsS) 
     533                    arIdx += 1 
     534                    dlgt(arIdx) = New GetIconImageDelegate(AddressOf GetIconImage) 
     535                    ar(arIdx) = dlgt(arIdx).BeginInvoke(post, imgs, imgsS, Nothing, Nothing) 
    528536 
    529537                    If _endingFlag Then Return "" 
     
    543551 
    544552                'テスト実装:DMカウント取得 
    545                 If intCnt = posts.Length And gType = GetTypes.GET_TIMELINE And page = 1 Then 
     553                If intCnt = posts.Length AndAlso gType = GetTypes.GET_TIMELINE AndAlso page = 1 Then 
    546554                    pos1 = strPost.IndexOf(_parseDMcountFrom, pos2, StringComparison.Ordinal) 
    547555                    If pos1 > -1 Then 
     
    559567                getDM = _getDm 
    560568            End If 
     569        Next 
     570 
     571        For i As Integer = 0 To arIdx 
     572            dlgt(i).EndInvoke(ar(i)) 
    561573        Next 
    562574 
     
    662674        Dim intCnt As Integer = 0   'カウンタ 
    663675        Dim listCnt As Integer = links.Count 
     676        Dim dlgt(20) As GetIconImageDelegate 
     677        Dim ar(20) As IAsyncResult 
     678        Dim arIdx As Integer = -1 
    664679 
    665680        For Each strPost As String In posts 
     
    784799 
    785800                    'Imageの取得 
    786                     post.ImageIndex = GetIconImage(post.ImageUrl, imgs, imgsS) 
     801                    arIdx += 1 
     802                    dlgt(arIdx) = New GetIconImageDelegate(AddressOf GetIconImage) 
     803                    ar(arIdx) = dlgt(arIdx).BeginInvoke(post, imgs, imgsS, Nothing, Nothing) 
    787804 
    788805                    If _endingFlag Then Return "" 
     
    804821                End If 
    805822            End If 
     823        Next 
     824 
     825        For i As Integer = 0 To arIdx 
     826            dlgt(i).EndInvoke(ar(i)) 
    806827        Next 
    807828 
     
    895916    End Function 
    896917 
    897     Private Function GetIconImage(ByVal pathUrl As String, ByVal imgs As Dictionary(Of String, Image), ByVal imgsS As ImageList) As Integer 
    898         If _endingFlag OrElse Not _getIcon Then Return -1 
    899         If imgsS.Images.ContainsKey(pathUrl) Then Return imgsS.Images.IndexOfKey(pathUrl) 
    900  
     918    Private Sub GetIconImage(ByVal post As PostClass, ByVal imgs As Dictionary(Of String, Image), ByVal imgsS As ImageList) 
     919        If _endingFlag OrElse Not _getIcon Then 
     920            post.ImageIndex = -1 
     921            Exit Sub 
     922        End If 
     923        If imgsS.Images.ContainsKey(post.ImageUrl) Then 
     924            post.ImageIndex = imgsS.Images.IndexOfKey(post.ImageUrl) 
     925            Exit Sub 
     926        End If 
     927 
     928        Dim sock As New MySocket("UTF-8", _uid, _pwd, _proxyType, _proxyAddress, _proxyPort, _proxyUser, _proxyPassword) 
    901929        Dim resStatus As String = "" 
    902         Dim img As Image = DirectCast(_mySock.GetWebResponse(pathUrl, resStatus, MySocket.REQ_TYPE.ReqGETBinary), System.Drawing.Image) 
    903         If img Is Nothing Then Return -1 
    904  
    905         imgs.Add(pathUrl, img)  '詳細表示用ディクショナリに追加 
     930        Dim img As Image = DirectCast(sock.GetWebResponse(post.ImageUrl, resStatus, MySocket.REQ_TYPE.ReqGETBinary), System.Drawing.Image) 
     931        If img Is Nothing Then 
     932            post.ImageIndex = -1 
     933            Exit Sub 
     934        End If 
    906935 
    907936        Dim bmp2 As New Bitmap(_iconSz, _iconSz) 
     
    910939            g.DrawImage(img, 0, 0, _iconSz, _iconSz) 
    911940        End Using 
    912         imgsS.Images.Add(pathUrl, bmp2) 
    913         Return imgsS.Images.IndexOfKey(pathUrl) 
    914     End Function 
     941 
     942        SyncLock iconLock 
     943            If imgsS.Images.ContainsKey(post.ImageUrl) Then 
     944                post.ImageIndex = imgsS.Images.IndexOfKey(post.ImageUrl) 
     945                Exit Sub 
     946            End If 
     947            imgs.Add(post.ImageUrl, img)  '詳細表示用ディクショナリに追加 
     948            imgsS.Images.Add(post.ImageUrl, bmp2) 
     949            post.ImageIndex = imgsS.Images.IndexOfKey(post.ImageUrl) 
     950        End SyncLock 
     951    End Sub 
    915952 
    916953    Private Function GetAuthKey(ByVal resMsg As String) As Integer 
     
    11961233        Dim resMsg As String = "" 
    11971234 
    1198         resMsg = DirectCast(_mySock.GetWebResponse(wedataUrl, resStatus, timeout:=10 * 1000), String) 'タイムアウト時間を10秒に設定 
     1235        resMsg = DirectCast(_mySock.GetWebResponse(wedataUrl, resStatus, timeOut:=10 * 1000), String) 'タイムアウト時間を10秒に設定 
    11991236        If resMsg.Length = 0 Then Exit Sub 
    12001237