Please Guide me abt Thread concept
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Please Guide me abt Thread concept

  1. #1
    Join Date
    Nov 2011
    Location
    India
    Posts
    179

    Please Guide me abt Thread concept

    Hi,

    I'm very bad in thread concept.I searched Google and got lot of examples about thread. But in my knowledge i couldn't understand B'cos the process was very heavy.

    Pls give any simple examples about thread.

    I'm using VC 2003 Dialog based MFC Application. I'm using serial communication using RS232(Comport 6) & RS485(Comport 4). I created a thread like below.

    Code
    ****

    BOOL CXRayFIDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();

    PTSobj.BoardIntialize(); //RS-232 Machine Interface -> Port initialize Using PSPort.InitPort(6,9600,'E',8,1); // Com6 & Baud Rate 9600
    AfxBeginThread(XRayThread,this); //Called Thread

    m_comm.put_CommPort(4);
    m_comm.put_Settings("9600,N,8,1");
    m_comm.put_InputLen(1);
    m_comm.put_InputMode(0);
    m_comm.put_RTSEnable(TRUE);
    m_comm.put_RThreshold(1);
    m_comm.put_PortOpen(true);

    SetTimer(1,1000,NULL);

    return TRUE;
    }

    UINT CXRayFIDlg::XRayThread(LPVOID XRAYLP)
    {
    CXRayFIDlg *XRDLG = (CXRayFIDlg *) XRAYLP;
    XRDLG->XRayThreadRun();
    return true;
    }

    void CXRayFIDlg::XRayThreadRun()
    {
    PTSobj.ObjSensor(); //Write method using comport 6
    PTSobj.ReadPortFromFrame(); //read method using comport 6
    CDialog::KillTimer(1);
    CDialog::KillTimer(2);
    CDialog::KillTimer(3);
    CDialog::KillTimer(4);
    CDialog::SetTimer(5,10,NULL);

    if(!XRAYThreadStop) //True only when i close my application
    AfxBeginThread(XRayThread,this);
    else
    AppQuitFlag = true;
    }

    void CXRayFIDlg::OnTimer(UINT nIDEvent)
    {
    if(nIDEvent == 1)
    {//Notify object sensor for every sec like FLT & MON
    if(ERROR_CHECK == TRUE && KillTmr == FALSE)
    {
    InsideTimer = TRUE;
    // Process ===> Read & Write process using com port 4
    InsideTimer = FALSE;
    }
    }

    if(nIDEvent == 2)
    {
    // Write process using com port 4
    CDialog::KillTimer(2);
    CDialog::SetTimer(1,1000,NULL);
    }

    if(nIDEvent == 3)
    {
    //Write process using com port 4
    CDialog::KillTimer(3);
    KillTmr = false;
    CDialog::SetTimer(1,1000,NULL);
    }
    if(nIDEvent == 4)
    {
    //Write process using com port 4
    CDialog::KillTimer(4);
    CDialog::SetTimer(1,1000,NULL);
    }

    if(nIDEvent == 5) // runs Delay
    {
    //Some Process
    CDialog::KillTimer(5);
    CDialog::SetTimer(6,100,NULL);
    }

    if(nIDEvent == 6) //runs Ontime
    {
    // Some Process
    CDialog::KillTimer(6);
    CDialog::SetTimer(1,1000,NULL);
    }
    CDialog::OnTimer(nIDEvent);

    }

    My application hanged using this single thread with timer concept.

    Am i going in the right path?

    how can i remove the timer and how can i use multithread process instead of timer?
    Regards,

    SaraswathiSrinath

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,517

    Re: Please Guide me abt Thread concept

    Have a look at these essays:
    Using Worker Threads
    Serial Port I/O
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2011
    Location
    India
    Posts
    179

    Re: Please Guide me abt Thread concept

    Hi Victor,

    Thanks for your reply. But the link doesn't open. Only the page was loading from yesterday.
    Regards,

    SaraswathiSrinath

  4. #4
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,538

    Re: Please Guide me abt Thread concept

    Link works for me...

    Try clearing your browser cache...
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,517

    Re: Please Guide me abt Thread concept

    Victor Nijegorodov

  6. #6
    Join Date
    Nov 2011
    Location
    India
    Posts
    179

    Re: Please Guide me abt Thread concept

    sorry sir.. i dont known, what is the problem.. but the page was not opening. i will try sir
    Regards,

    SaraswathiSrinath

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,039

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center