Re: Drawing from secondary thread erases resize corner in window? [solved, for now]
-
> the only reason I'm trying to draw on another thread
> is that my drawing is timer-driven, and the timer gets suspended if
> it's on the main thread and the user clicks on a menu or a scrollbar
> or some such thing.
You could also use [[NSRunLoop mainRunLoop] addTimer:yourTimer
forMode:NSEventTrackingRunLoopMode] and avoid another thread altogether. -
On Feb 28, 2008, at 1:46 PM, Nate Weaver wrote:>> You could also use [[NSRunLoop mainRunLoop] addTimer:yourTimer
>> forMode:NSEventTrackingRunLoopMode] and avoid another thread
>> altogether.
>>
Interesting... I hadn't thought of that. Don't I have to add another
timer to the NSDefaultRunLoopMode though? If I have to chose between
having two timers on the main thread that alternate, or one on a
secondary thread, I think I'll go with the extra thread.
Thanks,
Hank
Hank Heijink
<hank.list...> -
On Feb 28, 2008, at 1:49 PM, Hank Heijink wrote:>
> On Feb 28, 2008, at 1:46 PM, Nate Weaver wrote:
>
>>> You could also use [[NSRunLoop mainRunLoop] addTimer:yourTimer
>>> forMode:NSEventTrackingRunLoopMode] and avoid another thread
>>> altogether.
>>>
>
> Interesting... I hadn't thought of that. Don't I have to add another
> timer to the NSDefaultRunLoopMode though? If I have to chose between
> having two timers on the main thread that alternate, or one on a
> secondary thread, I think I'll go with the extra thread.
I don't believe so; I've used it in an app of my own with a single
timer to avoid the same issue you're having, with no apparent ill
effects. -
On Feb 28, 2008, at 2:56 PM, Nate Weaver wrote:>> Interesting... I hadn't thought of that. Don't I have to add
>> another timer to the NSDefaultRunLoopMode though? If I have to
>> chose between having two timers on the main thread that alternate,
>> or one on a secondary thread, I think I'll go with the extra thread.
>
> I don't believe so; I've used it in an app of my own with a single
> timer to avoid the same issue you're having, with no apparent ill
> effects.
That's not my experience. If I just add a timer for the
NSEventTrackingRunLoopMode, the only time that timer fires is when the
run loop is in event tracking mode, which is what I would expect. In
the NSDefaultRunLoopMode, that timer doesn't fire at all. Are you
doing something somewhere else to make this happen, or am I missing
something?
Thanks,
Hank
Hank Heijink
<hank.list...> -
On Feb 28, 2008, at 3:18 PM, Hank Heijink wrote:>
> On Feb 28, 2008, at 2:56 PM, Nate Weaver wrote:
>
>>> Interesting... I hadn't thought of that. Don't I have to add
>>> another timer to the NSDefaultRunLoopMode though? If I have to
>>> chose between having two timers on the main thread that alternate,
>>> or one on a secondary thread, I think I'll go with the extra thread.
>>
>> I don't believe so; I've used it in an app of my own with a single
>> timer to avoid the same issue you're having, with no apparent ill
>> effects.
>
>
> That's not my experience. If I just add a timer for the
> NSEventTrackingRunLoopMode, the only time that timer fires is when
> the run loop is in event tracking mode, which is what I would
> expect. In the NSDefaultRunLoopMode, that timer doesn't fire at all.
> Are you doing something somewhere else to make this happen, or am I
> missing something?
How did you create the timer? Via +scheduledTimerWithTimeInterval:...
or +timerWithTimeInterval:... ? If you use the latter, you'll have to
add it to NSDefaultRunLoopMode yourself. I just do something like:
myTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self
selector:@selector(doTimerStuff:) userInfo:nil repeats:YES] retain];
[[NSRunLoop mainRunLoop] myTimer forMode:NSEventTrackingRunLoopMode];
and it works during both modes (the retain there probably isn't
necessary in the general case, either). -
On Thu, Feb 28, 2008 at 9:18 PM, Hank Heijink <hank.list...> wrote:> That's not my experience. If I just add a timer for the
> NSEventTrackingRunLoopMode, the only time that timer fires is when the
> run loop is in event tracking mode, which is what I would expect. In
> the NSDefaultRunLoopMode, that timer doesn't fire at all. Are you
> doing something somewhere else to make this happen, or am I missing
> something?
You could try kCFRunLoopCommonModes (pre-Leopard) /
NSRunLoopCommonModes (post-Leopard). I believe that
NSDefaultRunLoopMode and NSEventTrackingRunLoopMode are in the default
common modes (along with NSEventTrackingRunLoopMode) but if not, you
can add common modes using CFRunLoopAddCommonMode().
Hamish -
On 29/02/2008, at 8:31 AM, Nate Weaver wrote:> On Feb 28, 2008, at 3:18 PM, Hank Heijink wrote:
>
>>
>> On Feb 28, 2008, at 2:56 PM, Nate Weaver wrote:
>>
>>>> Interesting... I hadn't thought of that. Don't I have to add
>>>> another timer to the NSDefaultRunLoopMode though? If I have to
>>>> chose between having two timers on the main thread that
>>>> alternate, or one on a secondary thread, I think I'll go with
>>>> the extra thread.
>>>
>>> I don't believe so; I've used it in an app of my own with a
>>> single timer to avoid the same issue you're having, with no
>>> apparent ill effects.
>>
>>
>> That's not my experience. If I just add a timer for the
>> NSEventTrackingRunLoopMode, the only time that timer fires is when
>> the run loop is in event tracking mode, which is what I would
>> expect. In the NSDefaultRunLoopMode, that timer doesn't fire at
>> all. Are you doing something somewhere else to make this happen,
>> or am I missing something?
>
>
> How did you create the timer? Via
> +scheduledTimerWithTimeInterval:... or +timerWithTimeInterval:... ?
> If you use the latter, you'll have to add it to
> NSDefaultRunLoopMode yourself. I just do something like:
>
> myTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self
> selector:@selector(doTimerStuff:) userInfo:nil repeats:YES] retain];
> [[NSRunLoop mainRunLoop] myTimer forMode:NSEventTrackingRunLoopMode];
>
> and it works during both modes (the retain there probably isn't
> necessary in the general case, either).
Hank, I can confirm this is true using
+scheduledTimerWithTimeInterval: and then adding the timer to the
NSEventTrackingRunLoopMode. No problems running the timer whether
events occur or not.
Ron -
Sent a message to the list from the wrong account, so it bounced. Here
it is:
On Feb 28, 2008, at 5:01 PM, Hamish Allan wrote:> You could try kCFRunLoopCommonModes (pre-Leopard) /
> NSRunLoopCommonModes (post-Leopard). I believe that
> NSDefaultRunLoopMode and NSEventTrackingRunLoopMode are in the default
> common modes (along with NSEventTrackingRunLoopMode) but if not, you
> can add common modes using CFRunLoopAddCommonMode().
That works beautifully. NSDefaultRunLoopMode and
NSEventTrackingRunLoopMode are indeed in the default common modes.
Thanks!
Hank


