Click here to Skip to main content
15,891,864 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to combine drawing Pin
Richard MacCutchan20-Mar-13 23:25
mveRichard MacCutchan20-Mar-13 23:25 
GeneralRe: How to combine drawing Pin
Wayne Gaylard20-Mar-13 23:29
professionalWayne Gaylard20-Mar-13 23:29 
AnswerRe: How to combine drawing Pin
TheRealRarius21-Mar-13 0:40
TheRealRarius21-Mar-13 0:40 
GeneralRe: How to combine drawing Pin
wgy_work21-Mar-13 14:15
wgy_work21-Mar-13 14:15 
QuestionReturn String from a CheckListBox Control Pin
PDTUM20-Mar-13 6:55
PDTUM20-Mar-13 6:55 
AnswerRe: Return String from a CheckListBox Control Pin
Eddy Vluggen20-Mar-13 7:59
professionalEddy Vluggen20-Mar-13 7:59 
AnswerRe: Return String from a CheckListBox Control Pin
PDTUM20-Mar-13 8:45
PDTUM20-Mar-13 8:45 
GeneralRe: Return String from a CheckListBox Control Pin
Eddy Vluggen20-Mar-13 12:15
professionalEddy Vluggen20-Mar-13 12:15 
QuestionHow declare in wcf a typed class to avoid serialization duplication Pin
anymalo20-Mar-13 1:21
anymalo20-Mar-13 1:21 
AnswerRe: How declare in wcf a typed class to avoid serialization duplication Pin
Eddy Vluggen20-Mar-13 1:33
professionalEddy Vluggen20-Mar-13 1:33 
GeneralRe: How declare in wcf a typed class to avoid serialization duplication Pin
anymalo20-Mar-13 3:06
anymalo20-Mar-13 3:06 
GeneralRe: How declare in wcf a typed class to avoid serialization duplication Pin
Eddy Vluggen20-Mar-13 7:46
professionalEddy Vluggen20-Mar-13 7:46 
QuestionThreading inside WCF Pin
Nand3219-Mar-13 20:46
Nand3219-Mar-13 20:46 
AnswerRe: Threading inside WCF Pin
AmitGajjar19-Mar-13 20:58
professionalAmitGajjar19-Mar-13 20:58 
GeneralRe: Threading inside WCF Pin
Nand3219-Mar-13 21:28
Nand3219-Mar-13 21:28 
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 

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.