Click here to Skip to main content
15,885,366 members
Home / Discussions / C#
   

C#

 
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 
I have a very simple WCF service, :

<br />
[service contract]<br />
<br />
public class Service1 : IService1<br />
    {<br />
<br />
        List<int> m_list = new List<int>();<br />
<br />
        public Service1()<br />
        {<br />
            for (int i = 0; i < 10; i++)<br />
            {<br />
                m_list.Add(i);<br />
            }<br />
        }<br />
<br />
<br />
[OperationContract]<br />
        public string GetData(int value)<br />
        {<br />
            for (int i = 0; i < 4; i++)<br />
            {<br />
                Thread t = new Thread(() => simpleThread(i));<br />
                t.Start();<br />
            }<br />
return "text"; // :|<br />
        }<br />
<br />
        void  simpleThread(int i_in) <br />
        {<br />
            Trace.WriteLine(m_list[i_in].ToString());<br />
        }<br />
<br />
}<br />

The code stores 0,1,2,3 as values inside m_list. So m_list[0] is 0, [1] is 1 .. [3] is 3.

And when we print it through "SimpleThread(int i)" Thread function, In the log it's supposed to be 0,1,2,3 but it's always like 2,2,3 or something weird. And the index passed in itself is wrong. It never passes 0,1. And sometimes it prints...

4 : 4
4 : 4
4 : 4
4 : 4


And the problem is random. I'm missing something very fundamental with threading on WCF. Any help please?

I would like to get it :

0 : 0

1 : 1

2 : 2

3 : 3

modified 20-Mar-13 3:24am.

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 
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 

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.