Click here to Skip to main content
15,890,123 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Windows Exlporer Pin
@Intersect☺™12-Apr-10 3:20
professional@Intersect☺™12-Apr-10 3:20 
GeneralRe: Windows Exlporer Pin
hellogany12-Apr-10 17:38
hellogany12-Apr-10 17:38 
GeneralRe: Windows Exlporer Pin
hellogany13-Apr-10 0:04
hellogany13-Apr-10 0:04 
QuestionGet default user name when "Run as administrator" Pin
sireesha_sree11-Apr-10 20:09
sireesha_sree11-Apr-10 20:09 
AnswerRe: Get default user name when "Run as administrator" Pin
«_Superman_»11-Apr-10 20:22
professional«_Superman_»11-Apr-10 20:22 
GeneralRe: Get default user name when "Run as administrator" Pin
sireesha_sree11-Apr-10 20:24
sireesha_sree11-Apr-10 20:24 
GeneralRe: Get default user name when "Run as administrator" Pin
«_Superman_»12-Apr-10 7:46
professional«_Superman_»12-Apr-10 7:46 
AnswerRe: Get default user name when "Run as administrator" Pin
_AnsHUMAN_ 12-Apr-10 1:31
_AnsHUMAN_ 12-Apr-10 1:31 
QuestionRe: Get default user name when "Run as administrator" Pin
David Crow12-Apr-10 4:44
David Crow12-Apr-10 4:44 
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 

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.