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?
Re: Please Guide me abt Thread concept
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.
Re: Please Guide me abt Thread concept
Link works for me...
Try clearing your browser cache...
Re: Please Guide me abt Thread concept
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
Re: Please Guide me abt Thread concept