N
Nak
Hi there,
I've come across quite an annoying bug after optimizing some of my code
(which sounds quite strange I know), but take this for a description of my
problem.
* I have a background thread continually monitoring a collection, when
items are available in the collection they are dealt with.
* The items in question are files for images, when files appear in the
collection the thread makes a thumbnail for it (which is associated with a
listview control) and then sets it to the relevant list view item.
Basically this method is used to enable me to process thumbnails in my
thumbnail browser *only* when they are visible in the client area. Anyway,
my problem comes *after* adding an image, consider the following code
------------------------------------------
Private Sub updateImageThumbnail(ByVal iItem As ListViewItem, ByVal
iThumbnail As Image)
SyncLock ilsThumbnails.Images
^This had no effect in resolving the bug
Dim pIntIndex As Integer = ilsThumbnails.Images.Count
Console.WriteLine("thumbnails = " &
ilsThumbnails.Images.Count.ToString)
Call ilsThumbnails.Images.Add(iThumbnail)
Console.WriteLine("after add thumbnails = " &
ilsThumbnails.Images.Count.ToString)
Call ilsSmall.Images.Add(smallImageIcon)
^This line has no relevance in this snipette
With iItem
Console.WriteLine("setting image index to " &
pIntIndex.ToString)
.ImageIndex = pIntIndex
^ The exception occurs here, I have copied and pasted the output
from the console below this code snipette
Console.WriteLine("image index set to " & pIntIndex.ToString)
End With
End SyncLock
End Sub
--------------------------------------------------------------------
thumbnails = 2
after add thumbnails = 3
setting image index to 2
The thread 'xObjects.thumbnailBrowser.pTrdUpdateThread' (0x1ac) has exited
with code 0 (0x0).
The thread 'xObjects.thumbnailBrowser.pTrdDrawThread' (0xc04) has exited
with code 0 (0x0).
System.ArgumentException: '-1' is not a valid value for 'index'.
at System.Windows.Forms.ListView.SetItemImage(Int32 index, Int32 image)
at System.Windows.Forms.ListViewItem.set_ImageIndex(Int32 value)
at NickPateman.xObjects.thumbnailBrowser.updateImageThumbnail(ListViewItem
iItem, Image iThumbnail) in E:\Personal\Development\VB
dotnet\NickPateman\xObjects\User controls\thumbnailBrowser.vb:line 373
at NickPateman.xObjects.thumbnailBrowser.pTrdDrawThread_Callback() in
E:\Personal\Development\VB dotnet\NickPateman\xObjects\User
controls\thumbnailBrowser.vb:line 648
--------------------------------------------------------------------
Any ideas as to what the hell is happening because I haven't got the
faintest idea?!?! All I can imagine is that the listview is still doing
something in the main thread. This problem is intermittent at the best of
times. I added the synclock the the imagelist but it had no effect on the
code, any ideas or work arounds? Maybe this is a known bug? (hopefully).
I'm going to have a few more hacks at it before I go to sleep I think,
isn't it typical how you come across a big problem when your just about
happy with it?
Nick.
I've come across quite an annoying bug after optimizing some of my code
(which sounds quite strange I know), but take this for a description of my
problem.
* I have a background thread continually monitoring a collection, when
items are available in the collection they are dealt with.
* The items in question are files for images, when files appear in the
collection the thread makes a thumbnail for it (which is associated with a
listview control) and then sets it to the relevant list view item.
Basically this method is used to enable me to process thumbnails in my
thumbnail browser *only* when they are visible in the client area. Anyway,
my problem comes *after* adding an image, consider the following code
------------------------------------------
Private Sub updateImageThumbnail(ByVal iItem As ListViewItem, ByVal
iThumbnail As Image)
SyncLock ilsThumbnails.Images
^This had no effect in resolving the bug
Dim pIntIndex As Integer = ilsThumbnails.Images.Count
Console.WriteLine("thumbnails = " &
ilsThumbnails.Images.Count.ToString)
Call ilsThumbnails.Images.Add(iThumbnail)
Console.WriteLine("after add thumbnails = " &
ilsThumbnails.Images.Count.ToString)
Call ilsSmall.Images.Add(smallImageIcon)
^This line has no relevance in this snipette
With iItem
Console.WriteLine("setting image index to " &
pIntIndex.ToString)
.ImageIndex = pIntIndex
^ The exception occurs here, I have copied and pasted the output
from the console below this code snipette
Console.WriteLine("image index set to " & pIntIndex.ToString)
End With
End SyncLock
End Sub
--------------------------------------------------------------------
thumbnails = 2
after add thumbnails = 3
setting image index to 2
The thread 'xObjects.thumbnailBrowser.pTrdUpdateThread' (0x1ac) has exited
with code 0 (0x0).
The thread 'xObjects.thumbnailBrowser.pTrdDrawThread' (0xc04) has exited
with code 0 (0x0).
System.ArgumentException: '-1' is not a valid value for 'index'.
at System.Windows.Forms.ListView.SetItemImage(Int32 index, Int32 image)
at System.Windows.Forms.ListViewItem.set_ImageIndex(Int32 value)
at NickPateman.xObjects.thumbnailBrowser.updateImageThumbnail(ListViewItem
iItem, Image iThumbnail) in E:\Personal\Development\VB
dotnet\NickPateman\xObjects\User controls\thumbnailBrowser.vb:line 373
at NickPateman.xObjects.thumbnailBrowser.pTrdDrawThread_Callback() in
E:\Personal\Development\VB dotnet\NickPateman\xObjects\User
controls\thumbnailBrowser.vb:line 648
--------------------------------------------------------------------
Any ideas as to what the hell is happening because I haven't got the
faintest idea?!?! All I can imagine is that the listview is still doing
something in the main thread. This problem is intermittent at the best of
times. I added the synclock the the imagelist but it had no effect on the
code, any ideas or work arounds? Maybe this is a known bug? (hopefully).
I'm going to have a few more hacks at it before I go to sleep I think,
isn't it typical how you come across a big problem when your just about
happy with it?
Nick.