Click here to Skip to main content
15,888,968 members
Home / Discussions / C#
   

C#

 
GeneralRe: Naming Controls Pin
SajjadZare17-Jun-10 6:01
SajjadZare17-Jun-10 6:01 
AnswerRe: Naming Controls Pin
yu-jian27-Jun-10 10:19
yu-jian27-Jun-10 10:19 
QuestionAssembelys Pin
future383916-Jun-10 15:20
future383916-Jun-10 15:20 
QuestionPerformance framework \ utility Pin
Berlus16-Jun-10 10:31
Berlus16-Jun-10 10:31 
AnswerRe: Performance measure on inline methods Pin
Berlus16-Jun-10 18:59
Berlus16-Jun-10 18:59 
QuestionCompact datagrid Pin
jashimu16-Jun-10 8:44
jashimu16-Jun-10 8:44 
AnswerRe: Compact datagrid Pin
hammerstein0516-Jun-10 10:33
hammerstein0516-Jun-10 10:33 
QuestionThread.Join Pin
Endien16-Jun-10 6:26
Endien16-Jun-10 6:26 
Please look at the code below :

private void button1_Click(object sender, EventArgs e)
        {
            for (int j = 0; j < 3; j++)
            {
                i = j;
                myCurThread = new Thread(new ThreadStart(myThread));
                myCurThread.Start();
                myCurThread.Join();
            }
        }

private void myThread()
        {
            string result = "";
            myComport = new ComPort();
            
            myComport.Device = "COM5";
            myComport.BaudRate = 115200;
            myComport.HardwareFlowControl = myComport.asFLOWCONTROL_ENABLE;
            myComport.DataBits = (short)myComport.asDATABITS_DEFAULT;
            myComport.StopBits = (short)myComport.asSTOPBITS_DEFAULT;
            myComport.Parity = (short)myComport.asPARITY_DEFAULT;

            myComport.ComTimeout = 8000;
            myComport.Open();

            string strUSSD = "AT+CUSD=1,\"" + "*444#" + "\",15";

            myComport.WriteString(strUSSD);

            if (myComport.LastError == 0)
            {
                result = myComport.ReadString();
                while(result.IndexOf("Result") == -1)
                {
                    result = myComport.ReadString();
                    Debug.WriteLine("i = " + i + " " + result);
                }
            }

            myComport.Close();
        }


Problem is, Thread.Join make the button "halt". This is understandable since Thread.Join will make main thread wait until the other thread is finish.

How to make so the button will not "halt" and the threads is run on order? (Thread 2 wait until thread 1 finish and so on).

Is there any alternative to Thread.Join?
AnswerRe: Thread.Join Pin
harold aptroot16-Jun-10 6:33
harold aptroot16-Jun-10 6:33 
GeneralRe: Thread.Join Pin
Endien16-Jun-10 6:48
Endien16-Jun-10 6:48 
GeneralRe: Thread.Join Pin
harold aptroot16-Jun-10 6:54
harold aptroot16-Jun-10 6:54 
GeneralRe: Thread.Join Pin
Endien16-Jun-10 7:12
Endien16-Jun-10 7:12 
GeneralRe: Thread.Join Pin
harold aptroot16-Jun-10 7:15
harold aptroot16-Jun-10 7:15 
GeneralRe: Thread.Join Pin
Chris Trelawny-Ross16-Jun-10 8:09
Chris Trelawny-Ross16-Jun-10 8:09 
GeneralRe: Thread.Join Pin
Endien16-Jun-10 8:31
Endien16-Jun-10 8:31 
AnswerRe: Thread.Join Pin
Adam R Harris16-Jun-10 6:37
Adam R Harris16-Jun-10 6:37 
GeneralRe: Thread.Join Pin
Endien16-Jun-10 6:52
Endien16-Jun-10 6:52 
GeneralRe: Thread.Join Pin
Adam R Harris16-Jun-10 8:18
Adam R Harris16-Jun-10 8:18 
GeneralRe: Thread.Join Pin
Endien16-Jun-10 8:26
Endien16-Jun-10 8:26 
GeneralRe: Thread.Join Pin
Adam R Harris16-Jun-10 8:46
Adam R Harris16-Jun-10 8:46 
GeneralRe: Thread.Join Pin
Endien16-Jun-10 8:57
Endien16-Jun-10 8:57 
AnswerRe: Thread.Join Pin
David Skelly16-Jun-10 6:47
David Skelly16-Jun-10 6:47 
GeneralRe: Thread.Join Pin
Endien16-Jun-10 8:35
Endien16-Jun-10 8:35 
AnswerRe: Thread.Join Pin
Luc Pattyn16-Jun-10 6:57
sitebuilderLuc Pattyn16-Jun-10 6:57 
GeneralRe: Thread.Join Pin
Endien16-Jun-10 7:30
Endien16-Jun-10 7: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.