Re: Stopping a Thread

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: brogers5884 (brogers5884_at_discussions.microsoft.com)
Date: 02/16/05


Date: Wed, 16 Feb 2005 14:09:04 -0800

I don't want to wait for it at all, I want it to exit immediately. In the
thread it just gets a recordset and then loops through the recordset and
loads each record into a custom drawn list control. If you try to close that
dialog while the thread is in it's loop loading the list control it blows up
in glorious fashion each and every time. I'm just trying to find some way to
tell that thread to stop doing anything and get out. Thanks for all of the
responses.

"Joseph M. Newcomer" wrote:

> This works only if the thread returning to the message pump. And the WaitForSingleObject
> is almost certainly fatal. The fact that it times out is even more suspicious. In fact,
> the piece of code is remarkably silly, in that it simply loops; INFINITE would have been a
> more effective timeout.
>
> But why do you have to wait for it at all?
>
> And putting it in the destructor is probably the wrong place to put it.
>
> You should shut the thread down in the OnClose handler. The destructor is far too late.
>
> Read my essay on worker threads on my MVP Tips site.
> joe
>
> On Wed, 16 Feb 2005 12:53:01 -0800, "brogers5884" <brogers5884@discussions.microsoft.com>
> wrote:
>
> >In my application I have some list controls that load fairly large amounts of
> >data, a few thousand records, or the query to get the records just take a
> >really large amount of time. So I created threads to load the list controls
> >instead of locking up the front end while it tries to load and it works like
> >a champ. My problem being is while the list is loading if the user closes
> >that dialog by switching to another screen or trying to close the dialog the
> >program errors out and shuts down. So I put code in the destructor of the
> >list control that initiates that the thread:
> >
> >m_pThread->PostThreadMessage(WM_USER_STOPTHREAD,0,0);
> >while(WaitForSingleObject(m_pThread->m_hThread, 1000) != WAIT_FAILED);
> >
> >Now I don't get immediate severe errors but the program hangs indefinitely
> >on the WaitForSingleObject command. Any ideas on how I can get that thread
> >to stop it's execution so the window can close gracefully and not lock up the
> >program? Thank you.
>
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
>



Relevant Pages

  • Re: search valors in access table
    ... The following code can be used to load either a listbox or a combobox ... ' Set the number of Columns = number of Fields in recordset ... Then you use the .BoundColumn property of the Combobox to specify the column that contains the required data. ...
    (microsoft.public.word.vba.userforms)
  • Re: Import a comma delimited file & match records
    ... I am sorry I can not load the file to big and contains info I ... So far I have been manuall copying and pasting the data. ... If so then I suggest using ADO to ... you could process each record of a recordset containing all data in the ...
    (microsoft.public.excel.programming)
  • RE: Datarepeater and Radiobuttons
    ... into a RecordSet each and when the user clicks the first option, ... load it's contents however you wish. ... I don't recommend that way because you would load the Queries into ... Once you knwo which query via the button ...
    (microsoft.public.vb.database)
  • Re: Poor perfomance with Spreadsheet OWC 10 with more than 200 columns
    ... then i load into the spreadsheet using XMLLOAD. ... HTML portion is what is slowing it down. ... > OWC Version: 10.0.0.2621 ... >>> to design the html table, reading from a Recordset. ...
    (microsoft.public.office.developer.web.components)
  • Re: VB application crashes
    ... When I load the form in Private Sub Form_ActivateI have the ... These are functions that load data into Listviews, ... Set rsjob = dbfASIC.OpenRecordset ... I used to use the same Public recordset rs all the time but I changed ...
    (microsoft.public.vb.general.discussion)