dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Thread

  1. #1
    Join Date
    Jul 2018
    Posts
    11

    Thread

    hello all,
    i have created a gui in vc++ with 2 buttons,one to start thread and other to stop thread.my code is
    void CMtDlg::OnButton1()
    {
    // TODO: Add your control notification handler code here

    //m_ctrlStatus.SetWindowText(L"Starting...");
    THREADSTRUCT *_param = new THREADSTRUCT;
    _param->_this = this;
    m_ctrlStatus.Format("Starting...%d",i);
    UpdateData(FALSE);

    mainthread=AfxBeginThread(MyThreadProc, _param); // <<== START THE THREAD

    m_op.Format("out");
    UpdateData(FALSE);

    //void CMtDlg::OnButton2();
    }

    void CMtDlg::OnButton2()
    {
    THREADSTRUCT *_param = new THREADSTRUCT;
    _param->_this = this;
    // TODO: Add your control notification handler code here
    //stopNow = TRUE;
    //KillTimer(1234);
    //m_ctrlStatus.Format("Stopped %d",i);
    //UpdateData(FALSE);
    mainthread = AfxEndThread(MyThreadProc, 0);
    m_op.Format("hi");
    UpdateData(FALSE);

    }

    but i am not sure about stopping the thread which i have started.how do i overcome this..plz help

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,258

    Re: Thread

    Well, if you are going to work with threads in MFC - start learning to do it the right way! This great Joe Newcomer's essay:
    Using Worker Threads will help you.
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)