Click here to Skip to main content
15,923,789 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: No idea where to start to find this bug... Pin
RobJones20-Jun-03 6:49
RobJones20-Jun-03 6:49 
GeneralRe: No idea where to start to find this bug... Pin
John M. Drescher20-Jun-03 6:54
John M. Drescher20-Jun-03 6:54 
GeneralRe: No idea where to start to find this bug... Pin
RobJones20-Jun-03 9:17
RobJones20-Jun-03 9:17 
GeneralRe: No idea where to start to find this bug... Pin
John M. Drescher20-Jun-03 9:31
John M. Drescher20-Jun-03 9:31 
GeneralRe: No idea where to start to find this bug... Pin
Ted Ferenc20-Jun-03 8:23
Ted Ferenc20-Jun-03 8:23 
GeneralA Story Pin
Ted Ferenc20-Jun-03 9:13
Ted Ferenc20-Jun-03 9:13 
GeneralRe: A Story Pin
RobJones20-Jun-03 9:24
RobJones20-Jun-03 9:24 
GeneralRe: No idea where to start to find this bug... Pin
basementman20-Jun-03 11:15
basementman20-Jun-03 11:15 
Often, it is easier and cleaner to simply create one (or more) thread at startup that sleep until an interval occurs, does it's processing, and goes back to sleep. The debugging is easier because you are not creating and destroying threads all the time and you don't have to deal with those issues surrounding thread creation. Consider the following thread function:

DWORD WINAPI BackgroundMailBoxMonitorThread(LPVOID pParams)
{
  AFX_MANAGE_STATE(AfxGetStaticModuleState());

  BACKGROUNDPARAMSTRUCT *pParamStruct = (BACKGROUNDPARAMSTRUCT *)pParams;

  DBConnection *pDBConn = new DBConnection;

  if (pDBConn)
    {
      int  iRunFrequency = 300;   // default to 5 minutes...

      if (pParamStruct->pApplication->GetUserTagValue("MailBoxMonitorBackgroundThreadRunFrequency",caSQLBuf))
        iRunFrequency = atoi(caSQLBuf);

      if (iRunFrequency < 30)  // check not more frequent than every 30 seconds..
        iRunFrequency = 30;

      pParamStruct->pApplication->GetSQLStatement(6015,caInBoxSQLBuf);

      if (pParamStruct->pApplication->GetSQLStatement(6010,caSQLBuf))
        {
          pParamStruct->pApplication->ParseSQL(caSQLBuf);

          int iSeconds = 0;

          while (!pParamStruct->bTerminateThread)
            {
              iSeconds++;
              if (iSeconds >= iRunFrequency)
                {
                  if (pParamStruct->pApplication->Connect2DB(pDBConn))
                    {
                      DBStatement *pStmt = pDBConn->ExecSQL(caSQLBuf);
                      if (pStmt)
                        {
                          CObList oAccounts;
                          MailBoxAccountInfo *pAccount;

                          while (pStmt->FetchNext())
                            {
                              pAccount = new MailBoxAccountInfo;

                              pAccount->m_lCompanyKey = pStmt->GetLong(1);
                              pAccount->m_cEMailSenderAccount = pStmt->GetString(2);
                              oAccounts.AddTail((CObject *)pAccount);
                            }

                          pStmt->EndSQL();

                          delete pStmt;

                          POSITION pPos = oAccounts.GetHeadPosition();
                          while (pPos)
                            {
                              pAccount = (MailBoxAccountInfo *)oAccounts.GetNext(pPos);
                              if (pAccount)
                                {
                                  // connect to mailbox and process any messages...
                                  CheckMailAccountForActivity(pAccount,pDBConn,caInBoxSQLBuf,pParamStruct->pApplication);

                                  delete pAccount;
                                }
                            }

                          oAccounts.RemoveAll();
                        }

                      pDBConn->Disconnect();

                      iSeconds = 0;
                    }
                }

              Sleep(1000);
            }
        }
      else
        {
          LogBackgroundProcessError(3,"Mailbox Monitor Company List SQL Statement Not Found!",pParamStruct->pApplication);
        }

      delete pDBConn;
    }

  if (!pParamStruct->bTerminateThread)
    pParamStruct->hThread = NULL;

  return 0;
}


It checks multiple mailboxes on an user-defined interval. It is NOT a UI thread, but sounds similar to what you are doing and if you need to update ui elements, you can pass messages to the foreground UI thread for screen updating.



 onwards and upwards... 
GeneralRe: No idea where to start to find this bug... Pin
RobJones20-Jun-03 11:31
RobJones20-Jun-03 11:31 
GeneralCTreeView Pin
frackasse20-Jun-03 5:05
frackasse20-Jun-03 5:05 
GeneralRe: CTreeView Pin
Rage20-Jun-03 5:19
professionalRage20-Jun-03 5:19 
GeneralRe: CTreeView Pin
RobJones20-Jun-03 5:31
RobJones20-Jun-03 5:31 
GeneralClickety... Pin
Ryan Binns20-Jun-03 16:34
Ryan Binns20-Jun-03 16:34 
GeneralMultiline TabControl display problem when adding a new tab Pin
Anonymous20-Jun-03 4:52
Anonymous20-Jun-03 4:52 
Generalmagic number for file type Pin
pnpfriend20-Jun-03 3:56
pnpfriend20-Jun-03 3:56 
GeneralRe: magic number for file type Pin
Johnny ²20-Jun-03 4:43
Johnny ²20-Jun-03 4:43 
GeneralRe: magic number for file type Pin
pnpfriend20-Jun-03 5:11
pnpfriend20-Jun-03 5:11 
GeneralRe: magic number for file type Pin
John M. Drescher20-Jun-03 6:16
John M. Drescher20-Jun-03 6:16 
GeneralRe: magic number for file type Pin
David Crow20-Jun-03 7:27
David Crow20-Jun-03 7:27 
GeneralRe: magic number for file type Pin
l a u r e n20-Jun-03 7:33
l a u r e n20-Jun-03 7:33 
GeneralRe: magic number for file type Pin
Ted Ferenc20-Jun-03 5:01
Ted Ferenc20-Jun-03 5:01 
GeneralIncreasing build number Pin
brianwelsch20-Jun-03 3:00
brianwelsch20-Jun-03 3:00 
GeneralRe: Increasing build number Pin
John M. Drescher20-Jun-03 3:40
John M. Drescher20-Jun-03 3:40 
GeneralRe: Increasing build number Pin
brianwelsch20-Jun-03 3:48
brianwelsch20-Jun-03 3:48 
GeneralRe: Increasing build number Pin
John M. Drescher20-Jun-03 3:50
John M. Drescher20-Jun-03 3:50 

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.