Re: Methods and Threading
- From: "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
- Date: Tue, 14 Feb 2006 15:13:27 -0500
FefeOxy wrote:
Dear Tom,
I am not sure if I understand what your new class does (what is
DECLARE_DYNAMIC. I read it but was confused).
My backgroundCalc function needs to access several private members such
as GPIBDevice1, 2, and the a static text member in the form (all of
which I've declared within the form). Therefore, using a static member
outside of the function is extremely undesirable. And my project being
of a managed type, I can't use friend to resolve this problem so
basically I'll need to have a bunch of delegates getting info from the
GPIBDevices and updating them in the form, that seems extremely
inefficient and long-winded.
Maybe it's time I re-structure the code.....
You actually have two problems. The first is that the thread function MUST be a static function. That problem is easy to solve: Pass your class 'this' pointer as the thread parameter. The static function can then use the pointer to call a nonstatic function. So with one extra step you can run your thread code in a member function.
2nd: Your thread will not be able to access your form or its child controls. With proper synchronization you can safely access your own variables, but not CWnd functions.
Yes, this can be awkward. It is part of the inherent limitations of using multithreading.
--
Scott McPhillips [VC++ MVP]
.
- Follow-Ups:
- Re: Methods and Threading
- From: FefeOxy
- Re: Methods and Threading
- From: Tom Serface
- Re: Methods and Threading
- References:
- Methods and Threading
- From: FefeOxy
- Re: Methods and Threading
- From: Tom Serface
- Re: Methods and Threading
- From: FefeOxy
- Methods and Threading
- Prev by Date: Re: Methods and Threading
- Next by Date: Re: Methods and Threading
- Previous by thread: Re: Methods and Threading
- Next by thread: Re: Methods and Threading
- Index(es):
Relevant Pages
|