c# - Using Thread.Start() on a method that takes parameters and returns values -


i call particular function on multiple threads follows:

int q = 0;         (int j = 0; j < number; j++)         {             int copy = q;             int copy1 = j;             if (!display_status[copy1].equals("no") && (selection == "all" || (selection == "all-lae" && license[copy1] != "") || (selection == "all-non lae" && license[copy1] == "") || (selection == "avionics -all" && trade[copy1] == "avionics") || (selection == "avionics-non lae" && trade[copy1] == "avionics" && license[copy1] == "") || (selection == "avionics-lae" && trade[copy1] == "avionics" && license[copy1] != "") || (selection == "airframe-all" && trade[copy1] == "airframes") || (selection == "airframe-non lae" && trade[j] == "airframes" && license[j] == "") || (selection == "airframe-lae" && trade[j] == "airframes" && license[j] != "")))             {                 int numberofprojects = numberc;                 string[] nameofproj = listc[0].toarray();                                     string[] name = list[0].toarray();//list of manpower names                 string man_name = name[copy1];//name of manpower                 list<string>[] lista = new list<string>[5];                 string[] status = listc[13].toarray();                 thread[copy] = new thread(() => {new_value[copy]=graph1threader(man_name,numberofprojects, nameofproj, status);});                 thread[copy].start();                 q++;              }         } 

graphthreader1() not seem returning value, elements of new_value hold value 0 after function called. may reason? there simple solution problem?

the cause graph1threader has not finished yet, 1 way can workaround calling thread[copy].join() defeat purpose of using threads @ all, way joining first thread @ end of loop, depends on want achieve code.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -