Question : COleDateTime::GetCurrentTi<wbr />me when used with Other than Main Thread Gives Exception and strange behaviour

I am using a Thread like this...
On the line       date2      =      COleDateTime::GetCurrentTime();
When i use F11 to switch into the function
it moves the execution to

BOOL CHtmlView::GetTheaterMode() const
although i am using a Dialog Based application
I found a solution to the above problem
by Using MFC in a static library
it works fine
but in
Using MFC as dynamic link library
the above problem pops up
Also calling or not calling
::AfxOleInit();
in the thread has no change in the above problem

The above solution is also not permanent
It fails in my other application in which i am trying to use it.

Is is mean that we can't use COleDateTime in other than main thread ?
Plz Help

void COledateTimeThreadDlg::OnButton1()
{
      ::AfxBeginThread(ThreadProc,this);      
}

UINT ThreadProc(LPVOID arg)
{
      //::AfxOleInit();
      COledateTimeThreadDlg      *pDlg;
      pDlg      =      (COledateTimeThreadDlg      *)arg;
      for(;;)
      {
            COleDateTimeSpan datespan;
            COleDateTime date1(::time(NULL)),date2;
            ::Sleep(100);
            date2      =      COleDateTime::GetCurrentTime();
            datespan      =      date2-date1;
      }

}

Answer : COleDateTime::GetCurrentTi<wbr />me when used with Other than Main Thread Gives Exception and strange behaviour

Maybe you should try 'Debug Multithreaded' rather than 'Debug Multithreaded DLL'. That might help you with DAO also because all runtime-functions get linked statically to your program, thus avoiding problems when using a single-threaded DLL like DAO.

If this doesn't help you could ignore it as long as Release works or you have to check all DLLs using Dependency Walker (depends.exe). If there is any mix of single-threaded and multi-threaded libraries, or Debug and Release DLLs, then this should be corrected. If you could spot dao.dll as reason, you may consider using ODBC classes (CDatabase, CRecordset), that are slower but thread-safe.

Hope that helps, Alex
Random Solutions  
 
programming4us programming4us