site_archiver@lists.apple.com Delivered-To: cocoa-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=aXpdMZux6AlQVh3kqotZFvTZEw906wPz7aaWRLVrlw8=; b=m3TwW8iDzwE36Bb5KeStXURdsHPSuSTdgia1JLkmhkgbNMDvUfgxyl3SHOwM81Umwn q4NQU67e1Drh2fAZq+zrcS+dg5MkuBdlqYRi4L5o1+LSopX+oCfyq6vQZUfqlNOCkWwB sdpFOB/IKisq055cAbCQ8uan1jfXfwwxkMbgN8p6Yw6ez9k8vJ+0li6HRpiR7uTeyjRF nvuse55GyRclKp/g4D3rEDDDZuUBxgc5kFVB3DTmStTAAXDwwJ+uUj8DEq327ukoQBfh d5m93HgRSGzg3U4DkfHhWAwnspIy7XreI/APlzbPc9zAEk1RYzSgbr7floyabUhHH/FI chlA== Many thanks for all the responses. In terms of what I'm doing, the NSTimer with 0.1 second granularity sounds like the best fit.
On 28 Jul 2017, at 7:26 pm, Charles Srstka <cocoadev@charlessoft.com> wrote:
If you’re using Swift <snip>
Still on Objective-C. Thanks though, I'll keep that bookmarked for when I venture into Swift!
On 28 Jul 2017, at 6:57 pm, Quincey Morris <quinceymorris@rivergatesoftware.com> wrote:
On Jul 28, 2017, at 08:57 , Mark Allan <markjallan@gmail.com <mailto:markjallan@gmail.com>> wrote:
I have an app with a helper tool that performs some lengthy process in a loop and reports progress to the user. It works out how many iterations of the loop will be needed, sets the progressbar.maxValue, and then increments the progress bar's value on each iteration.
Can you clarify this description? Is the helper tool running in a separate process, in which case how (and how often) is it reporting progress back to the app? Is it the helper tool that’s looping progressbar.maxValue times? What is the app doing while the helper tool is running?
Also, it seems like a “code smell” if the code that’s iterating millions of times is updating a progress bar directly. Actually, two issues:
1. In a MVC design, code that’s calculating like this is generally part of the model, and shouldn’t be aware of what UI element is reporting progress, even though the model may provide some progress information.
2. The iteration is presumably on a background thread, and it’s not clear how you transfer the progress information safely to the main thread.
The normal solution to #1 is some kind of observation (of the progress information), and to #2 is some kind of trampoline. Both of those techniques lend themselves to thinning the frequency of UI updates, so you have choices about how to do that.
I’m agnostic on timer vs. elapsed-time update thinning. Both are easy enough to do, once you figure out *where* to do them.
Apologies for the lack of detail/clarity - I simplified things for the sake of keeping the email short. The loop most definitely is not updating the progress bar directly. In fact, the helper tool is a separate process, communicating via NSXPCConnection, so it couldn't update it directly even if I wanted it to! Reducing the frequency of NSXPC messages was a secondary goal to figuring out how often the main app ought to be updating the UI. Mark _______________________________________________ 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/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com