Click here to Skip to main content
13,400,969 members (41,070 online)
Rate this:
Please Sign up or sign in to vote.
Hi Everyone....

i have two listViews,named listViewEven and listViewSquare, where listViewEven adds even number by looping and listViewSquare adds square of every items of listViewEven ,
means square of every items of listViewEven should be added to listViewSquare .

and i want to run two methods concurrently.

i have added two functions

void even()
   for (int i = 10; i < 20; i++)
        listViewEven.Items.Add(new ListViewItem(i.ToString()));
void square()
    foreach (ListViewItem list in listViewEven.Items)
        string no = list.Text;
        int no1 = Convert.ToInt32(no) * Convert.ToInt32(no);
        listViewSquare.Items.Add(new ListViewItem(no1.ToString()));

but how can i implement those functions ?

Is any modification is needed ?

Please provide some solution ...
Posted 26-Nov-12 0:26am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can't since square() depends on the result of even().
So you will have to merge them into one method with one loop. Inside that loop, do the 'even' stuff first and then the 'square' part.

// Method names should start with a capital letter and begin with a verb
void ProcessEvenAndSquare()
   for (int i = 10; i < 20; i++)
        listViewEven.Items.Add(new ListViewItem(i.ToString()));

        int square = i * i;
        listViewSquare.Items.Add(new ListViewItem(square.ToString()));

krushna chandra jena 26-Nov-12 6:06am
ok..i understand but in my problem one listview is depend upon another listview. that's why i have written that types of function .
please provide some solution ...
lukeer 26-Nov-12 7:40am
I thought I had been clear about what to do. But I improved my solution with a sample in code.
If that's not what you need, please elaborate on your question.
krushna chandra jena 26-Nov-12 8:38am
thanks for your suggestion but i want to use different loop . because i have two threads . by first thread one listview will add items(even no.) and by second thread another listview will add items(square of those even no.). and i want to run these two process parallely . What i have to do ?
lukeer 26-Nov-12 8:47am
You can't.

That's what I told you in the first two words of this solution.
Maybe "can't" is a bit too harsh, but there is no practical use for that, since the second method depends on the first one. This leads to so much synchronisation overhead between the two potential threads that you're better off sinlge-threaded.

Adding to that, you're using the main thread (a.k.a. GUI thread) in between. That will slow things down even further.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180218.2 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100