Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear all

i have a problem in my app
when listview update the application still not responding until the listview completed

i want to using threading in my code and when update listview progress bar run

this my code
FailChanel.Text = SucChannel.Text = "";
            successChannel = "";
            failedChannel = "";
            failCount = 0;
            listView1.Items.Clear();
            listView1.Enabled = false;
            string getdatafrommethod = GetDat(openFileDialog1);
            //check if user don't select the file 
            //if don't select file the return value will be empty 
            //and in the blew code will be return
            if (getdatafrommethod == "Empty")
                return;
           string[] yaArray = getdatafrommethod.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
             progressBar1.Value = 1;
            progressBar1.Visible = true;
            progressBar1.Maximum = yaArray.Length;
            
            foreach (string item in yaArray)
            {
                //the next code for the last line in the item 
                //when the last line is empty , continue the loop that will be finish
                //and when the file is empty
                if (item.Length == 0)
                    continue;
                listViewRow = item.Split(new string[] { "," }, StringSplitOptions.None); //Now we split on the semi colon to give us each item

                if (!this.CheckLogin(listViewRow[1], listViewRow[0]))
                {
                    failedChannel += "\r\n" + " Channel number : " + listViewRow[1] + " is failed to connect";
                    failCount++;
                    continue;
                }

                successChannel += listViewRow[0] + "," + listViewRow[1] + "\r\n";
                newItem = new ListViewItem(listViewRow[1]);
                newItem.SubItems.Add(listViewRow[0]);
                listView1.Items.Add(newItem);
               
                progressBar1.PerformStep();
            }
           
            
            listView1.Enabled = true;
            progressBar1.Visible = false;
            failedChannel += "\r\n" + " Total blocked channel is : "+failCount;
            SucChannel.Text = "Success channel : " + listView1.Items.Count;
            FailChanel.Text = "Failed channel : " + failCount;
            savefile(ChiledBlockChnannel, true, failedChannel);
            savefile(ChiledSucssesChannel, true, successChannel);
            
         

        }


this code work and progress bar working good but when application run and click button .. the application not responding and wait 2 min to complete the operation

so how to be fine to make another action on my form without not responding
Posted
Comments
Sergey Alexandrovich Kryukov 26-Oct-14 15:16pm    
Short answer: you are doing it wrong. :-)

Seriously, you did not show anything related to threads in your code.
So, to get help, you need to explain everything: why doing anything in different threads? what the threads are doing and why? which thread is a UI thread and which ones are not? what are you trying to achieve?

This is all possible, but you need to understand what and why. If some thread is working at something for two minutes, it's only natural that the result appear, say, in two minuted and 1 millisecond. It's only wrong if UI presentation along adds 2 minutes (which I simply cannot believe).

Are you familiar with UI thread invocation?

—SA
beljk 26-Oct-14 18:47pm    
not familiar With UI threading invocation
look
in button click i added this code
i have listview and i want to add data and in the same time i want progress bar show and performStem() method ...
first of code , in the GetDat(openFileDialog1) method return data in string array and sorting data to lines then in foreach loop line by line and get line and split in "," then checklogin method do somthing and if return true will do the code in if and return to foreach but if checklogin method return false will get data in listrow and but it in listviewitem then add it to listview control .....
when run the code is working fine and everything ok but if i drag the form it give me not responding until the code is end because the foreach take 2 min .. so i want this application respond not give me Not responding

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900