Professional Web Applications Themes

Newbie: Background Processing (Cocoa) - Mac Programming

I have a Cocoa application with a start and a stop button. When I press the start button a infinite loop should start and run till I press the stop button. But I only managed that either I can't press the stop button because the process is still running or I have to restart the loop every time it's finished. I searched the Cocoa doentation on apple.com but I'm not able to make head or tail of it. Thanks and sorry for wasting your time, ivo...

  1. #1

    Default Newbie: Background Processing (Cocoa)

    I have a Cocoa application with a start and a stop button. When I press the
    start button a infinite loop should start and run till I press the stop
    button. But I only managed that either I can't press the stop button
    because the process is still running or I have to restart the loop every
    time it's finished. I searched the Cocoa doentation on apple.com but I'm
    not able to make head or tail of it.

    Thanks and sorry for wasting your time,
    ivo
    ivo Guest

  2. #2

    Default Re: Newbie: Background Processing (Cocoa)

    ivo wrote: 

    You need to make your program multi-threaded. See the "Multithreading"
    topic in the cocoa docs.

    For your situation, see -detachNewThreadSelector:toTarget:withObject: in
    the NSThread doentation, and -performSelectorOnMainThread: in NSObject.

    -jcr
    John Guest

  3. #3

    Default Re: Newbie: Background Processing (Cocoa)

    In article <bluewin.ch>,
    ivo <arminundivo.ch> wrote:
     

    Welcome to the world of threads.

    What it appears that you need is at least two threads, one dealing with
    your UI and a second dealing with your processing. You then need some
    way of communicating from the UI thread to the processing thread that
    the stop button has been pressed.

    All fairly simple if you understand threads.

    I recommend you download, read and compile the following examples from
    the Apple Developers Samples...

    <http://developer.apple.com/samplecode/Sample_Code/Processes/TrivialThrea
    ds.htm>

    <http://developer.apple.com/samplecode/Sample_Code/Processes/SimpleThread
    s.htm>

    <http://developer.apple.com/samplecode/Sample_Code/Processes/PThreadSorts
    ..htm>

    This wil give you a start for understanding both NSThread and pthread at
    least well enough to accomplish what you want to do.
    Shawn Guest

  4. #4

    Default Re: Newbie: Background Processing (Cocoa)

    ivo <arminundivo.ch> wrote in message news:<bluewin.ch>... 

    If you have a tight infinite loop then that's all your process is
    doing and it cannot every get back to the OS where it scans for button
    presses. Now there are two ways to handle this, one way is to scan
    for the button press inside your infinite loop (and do the correct
    action) or run your infinite loop in a thread. A thread is the more
    elegant method, your program then appears to be doing multiple things
    (threads) at the same time.

    Here are some articles and howto's on the subject:

    http://cocoadevcentral.com/articles/000061.php - What they are and
    how they work

    simple examples

    http://cocoadevcentral.com/articles/000062.php - Building an app with
    them

    --jim
    Jim Guest

Similar Threads

  1. Newbie ?: need sample form processing scripts
    By cwrv in forum PHP Development
    Replies: 2
    Last Post: June 9th, 06:37 AM
  2. Cocoa newbie -- help with multiple windows
    By Larry Fransson in forum Mac Programming
    Replies: 11
    Last Post: August 15th, 07:42 AM
  3. Newbie : Buttons and Background
    By Nick C in forum Macromedia Fireworks
    Replies: 0
    Last Post: July 31st, 10:33 AM
  4. newbie cocoa file reading/writing files
    By Richard Humiston in forum Mac Programming
    Replies: 1
    Last Post: July 21st, 02:42 PM
  5. Newbie: How Do I Export Image without Background
    By nm in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 1
    Last Post: July 4th, 06:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139