OSDN Git Service

取得が間に合わないときに発言詳細のアイコンが空のままになる問題に対処
authorkiri_feather <kiri_feather@users.sourceforge.jp>
Fri, 21 Jan 2011 05:22:21 +0000 (05:22 +0000)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 18 Feb 2012 14:18:42 +0000 (23:18 +0900)
git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@1394 e39ad16e-3079-482e-bb30-4b4d378143b6

Tween/ImageDictionary.vb
Tween/ImageListViewItem.vb
Tween/Tween.vb

index 63754b6..57587e0 100644 (file)
@@ -39,18 +39,19 @@ Public Class ImageDictionary
     Private cachePolicy As New CacheItemPolicy()
     Private removedCount As Long = 0
 
-    Public Sub New(ByVal memoryCacheCount As Integer)
+    Public Sub New(ByVal cacheMemoryLimit As Integer)
         SyncLock Me.lockObject
             '10Mb,80%
+            'キャッシュチェック間隔はデフォルト値(2分毎)
             Me.innerDictionary = New MemoryCache("imageCache",
                                                  New NameValueCollection() From
                                                  {
-                                                     {"CacheMemoryLimitMegabytes", "10"},
+                                                     {"CacheMemoryLimitMegabytes", cacheMemoryLimit.ToString},
                                                      {"PhysicalMemoryLimitPercentage", "80"}
                                                  })
             Me.waitStack = New Stack(Of KeyValuePair(Of String, Action(Of Image)))
             Me.cachePolicy.RemovedCallback = AddressOf CacheRemoved
-            Me.cachePolicy.SlidingExpiration = TimeSpan.FromMinutes(30)
+            Me.cachePolicy.SlidingExpiration = TimeSpan.FromMinutes(30)     '30分参照されなかったら削除
         End SyncLock
     End Sub
 
index 9659215..dad2a34 100644 (file)
@@ -27,6 +27,7 @@ Public Class ImageListViewItem
     Inherits ListViewItem
 
     Private img As Image = Nothing
+    Public Event ImageDownloaded(ByVal sender As Object, ByVal e As EventArgs)
 
     Public Sub New(ByVal items() As String, ByVal imageKey As String)
         MyBase.New(items, imageKey)
@@ -42,6 +43,7 @@ Public Class ImageListViewItem
                                                                     Me.ListView.Created AndAlso
                                                                     Not Me.ListView.IsDisposed Then Me.ListView.Invoke(Sub()
                                                                                                                            If Me.Index < Me.ListView.VirtualListSize Then Me.ListView.RedrawItems(Me.Index, Me.Index, False)
+                                                                                                                           RaiseEvent ImageDownloaded(Me, EventArgs.Empty)
                                                                                                                        End Sub)
                                                             End Sub)
 
index 4d0a57a..ff0056a 100644 (file)
@@ -208,6 +208,8 @@ Public Class TweenMain
 
     Private WithEvents TimerTimeline As New System.Timers.Timer
 
+    Private WithEvents displayItem As ImageListViewItem
+
     'URL短縮のUndo用
     Private Structure urlUndo
         Public Before As String
@@ -1017,7 +1019,7 @@ Public Class TweenMain
         End If
 
         'アイコンリスト作成
-        TIconDic = New ImageDictionary(5000)
+        TIconDic = New ImageDictionary(50)
 
         tw.DetailIcon = TIconDic
 
@@ -4620,11 +4622,8 @@ RETRY:
         Return detailHtmlFormatHeader + orgdata + detailHtmlFormatFooter
     End Function
 
-    Private Sub SetUserPicture()
-        Thread.Sleep(1000)       ' 要調整
-        If Not String.IsNullOrEmpty(_curPost.ImageUrl) AndAlso TIconDic.ContainsKey(_curPost.ImageUrl) Then
-            UserPicture.Image = TIconDic(_curPost.ImageUrl)
-        End If
+    Private Sub DisplayItemImage_Downloaded(ByVal sender As Object, ByVal e As EventArgs) Handles displayItem.ImageDownloaded
+        If sender.Equals(displayItem) AndAlso displayItem.Image IsNot Nothing Then UserPicture.Image = displayItem.Image
     End Sub
 
     Private Overloads Sub DispSelectedPost()
@@ -4641,6 +4640,8 @@ RETRY:
         End If
 
         displaypost = _curPost
+        displayItem = DirectCast(_curList.Items(_curList.SelectedIndices(0)), ImageListViewItem)
+
         Dim dTxt As String = createDetailHtml(If(_curPost.IsDeleted, "(DELETED)", _curPost.OriginalData))
         If _curPost.IsDm Then
             SourceLinkLabel.Tag = Nothing
@@ -4685,11 +4686,6 @@ RETRY:
             UserPicture.Image = TIconDic(_curPost.ImageUrl)
         Else
             UserPicture.Image = Nothing
-
-            Dim proc As New Thread(New Threading.ThreadStart(Sub()
-                                                                 If Me.IsHandleCreated AndAlso Not Me.IsDisposed Then Invoke(New MethodInvoker(AddressOf SetUserPicture))
-                                                             End Sub))
-            proc.Start()
         End If
 
         NameLabel.ForeColor = System.Drawing.SystemColors.ControlText