OSDN Git Service

CachedImageをスレッドセーフに。
authorkiri_feather <kiri_feather@users.sourceforge.jp>
Wed, 8 Sep 2010 04:08:58 +0000 (04:08 +0000)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 18 Feb 2012 14:15:17 +0000 (23:15 +0900)
Setting.vbでInvokeする時、ウィンドウハンドル作成済みかの判定追加

git-svn-id: http://svn.sourceforge.jp/svnroot/tween/trunk@830 e39ad16e-3079-482e-bb30-4b4d378143b6

Tween/ImageCacheDictionary.vb
Tween/Setting.vb

index 4a0839a..45019fa 100644 (file)
@@ -6,7 +6,7 @@ Public Class ImageCacheDictionary
 
     Dim memoryCacheCount As Integer
     Private innerDictionary As Dictionary(Of String, CachedImage)
-    Private sortedKeyList As List(Of String)
+    Private sortedKeyList As List(Of String)    '古いもの順
 
     Public Sub New(ByVal memoryCacheCount As Integer)
         Me.innerDictionary = New Dictionary(Of String, CachedImage)(memoryCacheCount + 1)
@@ -144,33 +144,35 @@ Public Class ImageCacheDictionary
 
         Private img As Image = Nothing
         Private tmpFilePath As String = Nothing
+        Private Shared lockObject As New Object
 
         Public Sub New(ByVal img As Image)
             Me.img = img
         End Sub
 
-        Public Property Image As Image
+        Public ReadOnly Property Image As Image
             Get
-                If Me.img Is Nothing Then
-                    Me.img = Image.FromFile(Me.tmpFilePath)
-                End If
+                SyncLock lockObject
+                    If Me.img Is Nothing Then
+                        Me.img = Image.FromFile(Me.tmpFilePath)
+                    End If
 
-                Return Me.img
+                    Return Me.img
+                End SyncLock
             End Get
-            Set(ByVal value As Image)
-
-            End Set
         End Property
 
         Public Sub Chache()
-            If Me.tmpFilePath Is Nothing Then
-                Me.tmpFilePath = Path.GetTempFileName()
-                Me.img.Save(Me.tmpFilePath)
-            End If
-            If Me.img IsNot Nothing Then
-                Me.img.Dispose()
-                Me.img = Nothing
-            End If
+            SyncLock lockObject
+                If Me.tmpFilePath Is Nothing Then
+                    Me.tmpFilePath = Path.GetTempFileName()
+                    Me.img.Save(Me.tmpFilePath)
+                End If
+                If Me.img IsNot Nothing Then
+                    Me.img.Dispose()
+                    Me.img = Nothing
+                End If
+            End SyncLock
         End Sub
 
         Public Sub Dispose() Implements IDisposable.Dispose
index a79fc1a..d26dbab 100644 (file)
@@ -1854,7 +1854,7 @@ Public Class Setting
                     info.UsingCount = UsingApi
                     Dim proc As New Action(Of ApiInfo)(Sub(infoCount)
                                                            tw.GetInfoApi(infoCount) '取得エラー時はinfoCountは初期状態(値:-1)
-                                                           Me.Invoke(New Action(Of ApiInfo)(AddressOf DisplayApiMaxCount), infoCount)
+                                                           If Me.IsHandleCreated Then Me.Invoke(New Action(Of ApiInfo)(AddressOf DisplayApiMaxCount), infoCount)
                                                        End Sub)
                     proc.BeginInvoke(info, Nothing, Nothing)
                 Else