473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Major image list problem!

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(I nt32 value)
at NickPateman.xObjects.thumbnailBrowser.updateImageT humbnail(ListViewItem
iItem, Image iThumbnail) in E:\Personal\Development\VB
dotnet\NickPateman\xObjects\User controls\thumbnailBrowser.vb:line 373
at NickPateman.xObjects.thumbnailBrowser.pTrdDrawThre ad_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.
Nov 21 '05 #1
8 1441
Your problem may be that you are trying to access the listview control from
a thread other than the main (UI) thread. You need to make sure that ONLY
the main thread accesses the control (for the most part)

See articles such as:
http://www.thecodeproject.com/csharp...sthreading.asp

--
-Philip Rieck
http://philiprieck.com/blog/

-
"Nak" <a@a.com> wrote in message
news:e1**************@TK2MSFTNGP12.phx.gbl...
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(I nt32 value)
at NickPateman.xObjects.thumbnailBrowser.updateImageT humbnail(ListViewItem
iItem, Image iThumbnail) in E:\Personal\Development\VB
dotnet\NickPateman\xObjects\User controls\thumbnailBrowser.vb:line 373
at NickPateman.xObjects.thumbnailBrowser.pTrdDrawThre ad_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.

Nov 21 '05 #2
Hi Nick,

Is the updateImageThumbnail called on the backgroud working thread?
If so, I think we would better masharl the call on the main UI thread, it
is not recommend to modity UI control's property in the thread other than
main UI thread.
You may try to use the control.BeginInvoke or control.Invoke method to
marshal the call back to the UI control's thread(main UI thread).

Control.Invoke Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformscontrolclassinvoketopic.asp

Control.BeginInvoke Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemWindowsFormsControlClassBeginInvokeTopi c.asp

Private Sub ChangeText()
Dim rd As New Random
Me.Button1.Text = rd.Next().ToString() 'These code will run on
button1's thread, Main UI thread.
End Sub
Private Sub ThreadProc()
For i As Integer = 0 To 10
Me.Button1.Invoke(New MethodInvoker(AddressOf ChangeText))
Thread.Sleep(1000)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim th As New Thread(AddressOf ThreadProc)
th.Start()
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #3
Nak
Hi again,

While attempting to implementing this invoking thing, I found my
problem! The listview *was* being altered on another thread but nowhere
near where I was looking, sorry for all this! That's what working too late
does to your head!

Nick.

"Nak" <a@a.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Cheers Peter,

I shall start modifying it now and see how it reacts.

Nick.

""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:wA**************@cpmsftngxa06.phx.gbl...
Hi Nick,

Is the updateImageThumbnail called on the backgroud working thread?
If so, I think we would better masharl the call on the main UI thread, it
is not recommend to modity UI control's property in the thread other than
main UI thread.
You may try to use the control.BeginInvoke or control.Invoke method to
marshal the call back to the UI control's thread(main UI thread).

Control.Invoke Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformscontrolclassinvoketopic.asp

Control.BeginInvoke Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemWindowsFormsControlClassBeginInvokeTopi c.asp

Private Sub ChangeText()
Dim rd As New Random
Me.Button1.Text = rd.Next().ToString() 'These code will run on
button1's thread, Main UI thread.
End Sub
Private Sub ThreadProc()
For i As Integer = 0 To 10
Me.Button1.Invoke(New MethodInvoker(AddressOf ChangeText))
Thread.Sleep(1000)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim th As New Thread(AddressOf ThreadProc)
th.Start()
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.


Nov 21 '05 #4
Nak
Hi Phillip,

Cheers, strange how this hadn't come up sooner, but thats programming I
suppose!

Nick.

"Philip Rieck" <ju**@mckraken.com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
Your problem may be that you are trying to access the listview control
from a thread other than the main (UI) thread. You need to make sure that
ONLY the main thread accesses the control (for the most part)

See articles such as:
http://www.thecodeproject.com/csharp...sthreading.asp

--
-Philip Rieck
http://philiprieck.com/blog/

-
"Nak" <a@a.com> wrote in message
news:e1**************@TK2MSFTNGP12.phx.gbl...
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(I nt32 value)
at
NickPateman.xObjects.thumbnailBrowser.updateImageT humbnail(ListViewItem
iItem, Image iThumbnail) in E:\Personal\Development\VB
dotnet\NickPateman\xObjects\User controls\thumbnailBrowser.vb:line 373
at NickPateman.xObjects.thumbnailBrowser.pTrdDrawThre ad_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.


Nov 21 '05 #5
Nak
Cheers Peter,

I shall start modifying it now and see how it reacts.

Nick.

""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:wA**************@cpmsftngxa06.phx.gbl...
Hi Nick,

Is the updateImageThumbnail called on the backgroud working thread?
If so, I think we would better masharl the call on the main UI thread, it
is not recommend to modity UI control's property in the thread other than
main UI thread.
You may try to use the control.BeginInvoke or control.Invoke method to
marshal the call back to the UI control's thread(main UI thread).

Control.Invoke Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwindowsformscontrolclassinvoketopic.asp

Control.BeginInvoke Method
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemWindowsFormsControlClassBeginInvokeTopi c.asp

Private Sub ChangeText()
Dim rd As New Random
Me.Button1.Text = rd.Next().ToString() 'These code will run on
button1's thread, Main UI thread.
End Sub
Private Sub ThreadProc()
For i As Integer = 0 To 10
Me.Button1.Invoke(New MethodInvoker(AddressOf ChangeText))
Thread.Sleep(1000)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim th As New Thread(AddressOf ThreadProc)
th.Start()
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #6
Hi Nick,

If you still have any concern on this issue, please feel free to post here.
Cheers!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #7
Nak
Hi Peter,

Naah, all sorted now, I'm still accessing it from a background thread
but without this capability it would destroy the speed of my thumbnail
browser. It works very well now anyway, no problems since finding this bug.

Nick.

""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:VC**************@cpmsftngxa06.phx.gbl...
Hi Nick,

If you still have any concern on this issue, please feel free to post
here.
Cheers!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 21 '05 #8
Hi

I am glad that works for you.

Cheers!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
1
by: Laszlo Zsolt Nagy | last post by:
I would like to load image from a directory right into an image list. I wrote a simple library that loads the images in the directory and resizes them as needed before adding to the wx.ImageList....
6
by: Haines Brown | last post by:
I find that when I use list-style-image with galeon or mozilla, padding is inserted between the symbol image and the following list text, while under IE 5.0 it seems to be inserted before the image...
1
by: Ronny | last post by:
Hi, When ever I use image lists in a tree view the image list is behaving inconsistent. When I add images they first look good and clean, after I have close and open the code in the IDE the...
0
by: Oliver Elphick | last post by:
The attached proposal is written primarily for Debian. Its motivation is that the current package upgrade process is pretty flaky and also that the current packaging does not really provide for...
14
by: Zhang Weiwu | last post by:
Hello. I have been using word processor like OOO for nearly 10 years and such layout is very usual to me: gopher://sdf.lonestar.org/I/users/weiwu/ooo_wrap_correctly.png but I found it's very...
3
by: grzegorz.gazda | last post by:
Hi all Is there any limit of images which can be added to a image list. I have a problem with this control. I added an image list in design mode and I am adding images using code. Then I want to...
5
by: Roy Smith | last post by:
Be kind to me, I'm a CSS newbie... I've been playing with drupal, building a web site (hyc-test.org). I started with the "sky" theme, but didn't like the way it rendered list items in menus. ...
1
by: Angelo | last post by:
Hi all, I am having a very annoying problem when using an unordered list in my aspx page. I set a UL style to use a custom image as the list style image but it does not show in the screen. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.