> Le 20 oct. 2017 à 18:56, Quincey Morris <quinceymor...@rivergatesoftware.com> > a écrit : > > On Oct 20, 2017, at 03:23 , Mark Allan <markjal...@gmail.com> wrote: >> >> That worked with the block-based NSTimer API but not the selector-based API. >> I tried changing it to 'currentRunLoop' which got rid of the crash, but the >> timer never fired. > > This is pure guesswork, but I suspect this is what was going on: > > — When you scheduled the timer on the main run loop, it was actually being > scheduled on the main app’s run loop. When it was block based, only the block > had to be passed across the XPC interface (which somehow works), but when it > was selector-based, the timer itself had to be passed (which doesn’t work). > Admittedly this is a pretty silly explanation, but it may have some relation > to the truth. > > — When you scheduled the timer on the current run loop, everything was fine > either way, except the run loop *wasn’t running* in the XPC thread, so the > timer never fired. > > This is similar to a problem that came up on the developer forums a few weeks > ago. A developer was using Disk Arbitration callbacks to monitor volumes > being mounted, and tried to move that code to an XPC process. The callback > was scheduled on the run loop, yet it was never called. There was more recent > API that was block-based instead, and that turned out to work fine in an XPC > process. The fact that scheduling on the run loop didn’t crash indicated that > there *was* a run loop, but the fact that the callbacks didn’t fire suggested > that it wasn’t running.
There is always a runloop as it is created lazily when accessing it. So the scheduling will always work. But if the current thread does not call -[NSRunLoop run] (or a variant), it will never be dispatched. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com