On Jun 20, 2011, at 3:33 PM, Conrad Shultz wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 6/20/11 3:17 PM, James Merkel wrote:
I am trying to come up with a way of not using threads (because of the potential problems). All I really want to do is give the user a way of
canceling the long process. I was thinking of just sampling a cancel
state variable every time through the loop. Of course that introduces
overhead, and there's the possibility the user cancels on a particularly
long duration loop cycle and wouldn't quickly see a response to his
cancel. I would think there is some simpler method than using threads
for handling this fairly common situation of a handling a long process.

Please don't do this.

If the main thread is blocked by whatever your process is doing the UI
will not respond.  You won't be able to set a cancel state variable
while the main thread is blocked - it's what handles responding to,
e.g., button clicks!

I'd say that in general your application should be event driven; let the run loop do its thing and handle events as appropriate. About the only
time I can think of to use a state variable as you describe is in, for
example, an NSOperation, to mark it as canceled. But such an operation
would itself be running on a separate thread (most commonly).

While we often make it sound scary, threading needn't be difficult to
implement. You have GCD, you have NSOperation/NSOperationQueue; between the two you have quite a bit of power with minimal lines of code needed. Depending on what you need to do in your loop, it might be as simple as
calling dispatch_async().

Of course, if you need to handle locking, mutual exclusion, thread
coordination, etc., THEN threading can start to get tough, but it
doesn't really sound like this applies to you.

Can you remind me what you are trying to accomplish (broad overview)?

- --
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3/ysUACgkQaOlrz5+0JdU97wCdGwNBFZKMCdTgHediaXlQumgf
3ZUAnjDaoQrFHxAghq48tDOFlm6NdVW4
=5gh7
-----END PGP SIGNATURE-----

I guess that's right -- I'll never capture the user's cancel.

I'm opening all digital camera files in a folder (JPEG, TIF, etc), extracting a thumbnail and some Exif data, and putting the data in a TableView. The time consuming part is finding the thumbnails in the files.

Jim Merkel

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to