Click here to Skip to main content
15,886,074 members
Home / Discussions / C#
   

C#

 
GeneralRe: Threading inside WCF Pin
AmitGajjar19-Mar-13 22:26
professionalAmitGajjar19-Mar-13 22:26 
GeneralRe: Threading inside WCF Pin
Nand3219-Mar-13 23:02
Nand3219-Mar-13 23:02 
GeneralRe: Threading inside WCF Pin
AmitGajjar19-Mar-13 23:05
professionalAmitGajjar19-Mar-13 23:05 
GeneralRe: Threading inside WCF Pin
Nand3219-Mar-13 23:07
Nand3219-Mar-13 23:07 
GeneralRe: Threading inside WCF Pin
AmitGajjar19-Mar-13 23:12
professionalAmitGajjar19-Mar-13 23:12 
AnswerRe: Threading inside WCF Pin
Manfred Rudolf Bihy19-Mar-13 21:18
professionalManfred Rudolf Bihy19-Mar-13 21:18 
GeneralRe: Threading inside WCF Pin
Nand3219-Mar-13 21:29
Nand3219-Mar-13 21:29 
GeneralRe: Threading inside WCF Pin
Manfred Rudolf Bihy19-Mar-13 22:09
professionalManfred Rudolf Bihy19-Mar-13 22:09 
While rummaging around in my brain a bit I suddenly had a case of deja vu.
The problem lies here in closures, lambda expressions and their interaction with threading.
I'm not sure if I found the post I read a couple of years ago, but here it goes:
Lambda expressions, captured variables and threading[^].
Especially enlightening is answer 2.

Thus please try to rewrite your code in this manner:

C#
[OperationContract]
public string GetData(int value)
{
    for (int i = 0; i < 4; i++)
    {
        Thread t = new Thread(() => {
             int j = i;       // not quite sure if this is needed,
                              // but try leaving it out and see what happens.
             simpleThread(j); // if you leave out the above statement change j to i on this line
        });
        t.Start();
    }
    return ""; // An empty string is also a string ;)
}


Regards,
— Manfred

"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian


GeneralRe: Threading inside WCF Pin
Nand3219-Mar-13 22:30
Nand3219-Mar-13 22:30 
GeneralRe: Threading inside WCF Pin
Manfred Rudolf Bihy19-Mar-13 22:51
professionalManfred Rudolf Bihy19-Mar-13 22:51 
GeneralRe: Threading inside WCF Pin
Nand3219-Mar-13 23:05
Nand3219-Mar-13 23:05 
GeneralRe: Threading inside WCF Pin
Steve4419-Mar-13 23:19
Steve4419-Mar-13 23:19 
GeneralRe: Threading inside WCF Pin
Nicholas Marty20-Mar-13 2:24
professionalNicholas Marty20-Mar-13 2:24 
AnswerRe: Threading inside WCF Pin
Steve4419-Mar-13 22:07
Steve4419-Mar-13 22:07 
GeneralRe: Threading inside WCF Pin
Nand3219-Mar-13 22:30
Nand3219-Mar-13 22:30 
AnswerRe: Threading inside WCF Pin
jschell20-Mar-13 8:49
jschell20-Mar-13 8:49 
GeneralRe: Threading inside WCF Pin
Steve4420-Mar-13 9:56
Steve4420-Mar-13 9:56 
QuestionBest way to integrate PowerPoint or slideviewer in C# Pin
Sachin k Rajput 19-Mar-13 20:22
Sachin k Rajput 19-Mar-13 20:22 
AnswerRe: Best way to integrate PowerPoint or slideviewer in C# Pin
Manfred Rudolf Bihy19-Mar-13 21:22
professionalManfred Rudolf Bihy19-Mar-13 21:22 
GeneralRe: Best way to integrate PowerPoint or slideviewer in C# Pin
Sachin k Rajput 19-Mar-13 22:51
Sachin k Rajput 19-Mar-13 22:51 
GeneralRe: Best way to integrate PowerPoint or slideviewer in C# Pin
DaveyM6920-Mar-13 0:26
professionalDaveyM6920-Mar-13 0:26 
GeneralRe: Best way to integrate PowerPoint or slideviewer in C# Pin
Sachin k Rajput 20-Mar-13 1:26
Sachin k Rajput 20-Mar-13 1:26 
Questionhow to index all the data from disk Pin
Member 888804419-Mar-13 7:53
Member 888804419-Mar-13 7:53 
AnswerRe: Sir, Dan Letecky post Desktop Search Application: Part 2 Pin
Dave Kreskowiak19-Mar-13 8:12
mveDave Kreskowiak19-Mar-13 8:12 
QuestionMaintaining Variables Pin
clugsy6419-Mar-13 5:38
clugsy6419-Mar-13 5:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.