How do I Invoke a ListViewItem thread?

T

Tom P.

I'm trying to update some information in a ListViewItem.SubItem but
the data is compiled on a different thread then passed over to the
ListViewItem. The problem is I keep getting a cross-thread exception.
I can't for the life of me find ListViewItem.Invoke() method to use.
What should I be using to obtain the UI thread? Thanks.

Tom P.
 
R

Rene

Invoke is part of the "Control" class, it's there, not sure why you can't
find it.



No matter what, is my understanding that you can use whatever control you
want to run your code, all you are doing is telling the UI thread to run a
chunk of the code, you can even use "this.Invoke" if you wanted to.
 
M

Mufaka

Use the ListViewItem.ListView property. ListViewItem is just an item in
the ListViewItemCollection.
 
T

Tom P.

That was it! Thanks for the help.

Now how do I pass a parameter to a delegate method using Invoke? In
other words...

public delegate void SetDirsizeDelegate(long DirLength);


public void Callback(long SizeInBytes)
{
SetDirsizeDelegate DirSizeDelegate;

DirSizeDelegate = new SetDirsizeDelegate(SetDirsize);

ListView.Invoke(DirSizeDelegate); //... or ...
ListView.Invoke(DirSizeDelegate(SizeInBytes)) //... or ...
//...Or do I pass it before the invoke?
//... How do I get the SizeInBytes parameter to the method
SetDirsize using Invoke??
}


Tom P.
 
M

Mufaka

No problem, glad to help.

Invoke's second parameter is params object[]. You can do
ListView.Invoke(DirSizeDelegate, SizeInBytes);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top