Click here to Skip to main content
15,881,248 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionWIN32 c++ Pin
humais11-Apr-10 19:29
humais11-Apr-10 19:29 
AnswerRe: WIN32 c++ Pin
«_Superman_»11-Apr-10 20:04
professional«_Superman_»11-Apr-10 20:04 
GeneralRe: WIN32 c++ Pin
humais11-Apr-10 20:13
humais11-Apr-10 20:13 
GeneralRe: WIN32 c++ Pin
«_Superman_»11-Apr-10 20:16
professional«_Superman_»11-Apr-10 20:16 
GeneralRe: WIN32 c++ Pin
humais11-Apr-10 20:33
humais11-Apr-10 20:33 
QuestionOpenGL Pin
ratprita11-Apr-10 19:09
ratprita11-Apr-10 19:09 
AnswerRe: OpenGL Pin
Cedric Moonen11-Apr-10 20:52
Cedric Moonen11-Apr-10 20:52 
QuestionHow to set up a long time of the interval timer ? [modified] Pin
wangningyu11-Apr-10 17:21
wangningyu11-Apr-10 17:21 
Hello,everybody !

I want to set a 25 hours timer in the dialog based project.There will be plenty of database operation in the menber function.

I used this way:

1、SetTimer

when I used it ,the window interface always death after 10 minutes ago.

2、Multi-Threading

but it faild to ,when the function execute several times,it no longer to run anymore.

DWORD CTestDlg::ThreadProc(LPARAM lParam)
{
    typedef     BOOL (_stdcall *MYSWITCH)();
    MYSWITCH	MySwitchToThread;
    HINSTANCE	hInst = LoadLibrary("Kernel32.dll");

    if (hInst != NULL)
    MySwitchToThread = (MYSWITCH)GetProcAddress(hInst, "SwitchToThread");

    if(!MySwitchToThread)
    	return -1;

    CTestDlg *pDlg = (CTestDlg *)lParam;
    TRACE( "Work thread pDlg --- %d\n ",pDlg); 

    UINT	oldTickCount,newTickCount;
    oldTickCount = GetTickCount();
    while(TRUE)
    {
        while(TRUE)
        {
            newTickCount = GetTickCount();
            if(newTickCount - oldTickCount >= 10000)
            {
                oldTickCount = newTickCount;
                break;
            }
            else
		MySwitchToThread();
        }
        
        // the thread run info
        CFile	file("MyThread.txt",CFile::modeReadWrite|CFile::modeNoTruncate);
        CTime   time;
        CString	str="";
        time = CTime::GetCurrentTime();
        str.Format("%d-%02d-%02d %02d:%02d:%02d  Thread Running...\r\n",
                time.GetYear(),time.GetMonth(),time.GetDay(),
		time.GetHour(),time.GetMinute(),time.GetSecond());
        file.SeekToEnd();
        file.Write(str,str.GetLength());  
        file.Flush();  
        file.Close();
        Sleep(100);
        
        // then call the member function
        pDlg->Fun1(); // Read some one
        Sleep(100);
        pDlg->Fun2(); // Write some one
        return 0;
    }
    return 0;
}


then run the thread:

BOOL CTestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	......
	CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadProc,this,0,NULL);
}


There a better way ?
modified on Sunday, April 11, 2010 11:30 PM

AnswerRe: How to set up a long time of the interval timer ? Pin
«_Superman_»11-Apr-10 20:07
professional«_Superman_»11-Apr-10 20:07 
GeneralRe: How to set up a long time of the interval timer ? Pin
wangningyu11-Apr-10 20:37
wangningyu11-Apr-10 20:37 
AnswerRe: How to set up a long time of the interval timer ? Pin
David Crow12-Apr-10 2:58
David Crow12-Apr-10 2:58 
GeneralRe: How to set up a long time of the interval timer ? Pin
wangningyu12-Apr-10 3:13
wangningyu12-Apr-10 3:13 
QuestionIs there a Parent Child realtionship with regards to threads Pin
ForNow11-Apr-10 14:23
ForNow11-Apr-10 14:23 
AnswerRe: Is there a Parent Child realtionship with regards to threads Pin
Chris Losinger11-Apr-10 14:33
professionalChris Losinger11-Apr-10 14:33 
GeneralRe: Is there a Parent Child realtionship with regards to threads Pin
@Intersect☺™12-Apr-10 1:28
professional@Intersect☺™12-Apr-10 1:28 
AnswerRe: Is there a Parent Child realtionship with regards to threads Pin
Stephen Hewitt11-Apr-10 17:15
Stephen Hewitt11-Apr-10 17:15 
GeneralRe: Is there a Parent Child realtionship with regards to threads Pin
ForNow11-Apr-10 17:46
ForNow11-Apr-10 17:46 
GeneralRe: Is there a Parent Child realtionship with regards to threads Pin
KingsGambit11-Apr-10 18:38
KingsGambit11-Apr-10 18:38 
GeneralRe: Is there a Parent Child realtionship with regards to threads Pin
Stephen Hewitt12-Apr-10 4:26
Stephen Hewitt12-Apr-10 4:26 
QuestionOpen Source Projects? Pin
Jasonweber71911-Apr-10 11:03
Jasonweber71911-Apr-10 11:03 
AnswerRe: Open Source Projects? Pin
Maximilien11-Apr-10 12:22
Maximilien11-Apr-10 12:22 
AnswerRe: Open Source Projects? Pin
Fareed Rizkalla11-Apr-10 15:11
Fareed Rizkalla11-Apr-10 15:11 
AnswerRe: Open Source Projects? Pin
Saurabh.Garg11-Apr-10 17:32
Saurabh.Garg11-Apr-10 17:32 
QuestionListView / Win32 Pin
Fareed Rizkalla11-Apr-10 9:44
Fareed Rizkalla11-Apr-10 9:44 
AnswerRe: ListView / Win32 Pin
Richard MacCutchan11-Apr-10 22:28
mveRichard MacCutchan11-Apr-10 22:28 

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.