You cannot vote on your own post

I have loaded many images in a listview using ImageList in c#. When many many images are loaded then it takes a long time. So I call the method in backgroundworker. In the backgroundworker I had to add images to ImageList and add ImageList to ListView. So I have used safeinvoke() method listView1.SafeInvoke(d=>d.Items.Add(item)).
. Everything works fine. Images are displayed one by one in the listview. But the problem is the listview is continuously refreshing when a new item is added. This refreshing seems disturbing to the user. When I have added the item without using background worker (listView1.Items.Add(item)) then it worked fine. It was added one after another smoothly without refreshing. I want to add item without refreshing the listview.

Where is the problem? Is the problem of backgroundworker or the SafeInvoke () method? How to solve it?

sample code:

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
string[] fileNames = Directory.GetFiles(@"E:\Image");

foreach (string flName in fileNames)

Bitmap btmap = (Bitmap)Image.FromFile(flName);
//imageList.Images.Add(newBtmap); when backgroundworker was not used
ListViewItem item;
item = new ListViewItem();
item.ImageIndex = scanNo - 1;
item.Text = scanNo.ToString();

// listView1.Items.Add(item); when backgroundworker was not used


public static TResult SafeInvoke<T, TResult>(this T isi, Func<T, TResult> call) where T : ISynchronizeInvoke
            if (isi.InvokeRequired) {
                IAsyncResult result = isi.BeginInvoke(call, new object[] { isi });
                object endResult = isi.EndInvoke(result); return (TResult)endResult;
                return call(isi);

        public static void SafeInvoke<T>(this T isi, Action<T> call) where T : ISynchronizeInvoke
            if (isi.InvokeRequired) isi.BeginInvoke(call, new object[] { isi });

Recommended Answers

All 2 Replies

try ajax with web service or ajax with wcf

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.