Professional Web Applications Themes

NSThread - NSNotefiaction - NSRunLoop - Mac Programming

Hello NG In my application I try to detach a slower background process form the UI with the help of NSThreads. In my NSWindowController -Class I call a [NSThread detachNewThreadSelector:SEL withObject:aObject .... to detach the function with the slower progress. If this function is ready, I post a notefication before the thread exits. On the other hand I have a observer which should show me the results in the UI. All the data is there but it is not shown in the WebView. If I step to the next object and back to aObject (get the next run loop), it ...

  1. #1

    Default NSThread - NSNotefiaction - NSRunLoop

    Hello NG
    In my application I try to detach a slower background process form the UI with the help
    of NSThreads.
    In my NSWindowController -Class I call a [NSThread detachNewThreadSelector:SEL
    withObject:aObject ....
    to detach the function with the slower progress. If this function is ready, I post a
    notefication before the thread exits. On the other hand I have a observer which should show me the
    results in the UI. All the data is there but it is not shown in the WebView. If I step to the next
    object and back to aObject (get the next run loop), it is shown correct what tells me that it
    was processed well. Dose the thread die to quick ? If I keep the thread alive with a
    [[NSRunLoop] currentRunLoop] run] everything works fine. Maybe there is a way to kill the thread
    later ? Or do I have to use DO ?
    Is there a good example for the perfromSelectorOnMainThread method?

    Thank you for time and help

    Florian Guest

  2. #2

    Default Re: NSThread - NSNotefiaction - NSRunLoop

    Florian Zschocke <de> wrote: 
    Found it my self, performSelectorOnMainThread did it and I am simple threaded now. I
    think for me that is good enough course there is no communication between threads and the
    only thing I need is, that if the information is there it should be shown. If not, you can
    wait or comeback later. The only thing I have to care about is which data is processed in the
    moment. I do that very simple and store them into a array and removing them if they are finished
    , so that they can't be processed twice.

    Florian

    Florian Guest

  3. #3

    Default Re: NSThread - NSNotefiaction - NSRunLoop

    On Sat, 17 Jul 2004, Florian Zschocke wrote:
     

    NSNotification is a pretty simply mechanism, and it doesn't do
    cross-thread communication. When you post a notification from a different
    thread, the observers recieve it in that same thread, regardless of which
    thread they registered from, and this is probably why you were having
    trouble.
    Michael Guest

  4. #4

    Default Re: NSThread - NSNotefiaction - NSRunLoop

    Michael Ash <com> wrote: 
    On Sat, 17 Jul 2004, Florian Zschocke wrote: 

    Yes, I red the sample
    http://www.cocoadev.com/index.pl?NotificationsAcrossThreads and did not realize that this will only work when you have permanent threads with a own
    RunLoop, which leads me to my next question:
    Is it "expensive" to create new threads ?

    Thank you Michael for always being there - for people like you I write my program and
    perhaps I can help people to help.

    Florian Guest

  5. #5

    Default Re: NSThread - NSNotefiaction - NSRunLoop

    On Sat, 17 Jul 2004, Florian Zschocke wrote:
     

    As with all things, "it depends". You shouldn't be creating zillions of
    them all over the place, but if you spawn of one or two, or ten, to handle
    a user-prompted action, it's fine.
     

    I'm glad to be of service.
    Michael Guest

Similar Threads

  1. Problem with NSThread and usleep
    By Eric in forum Mac Programming
    Replies: 7
    Last Post: February 29th, 05:22 AM
  2. Yield with NSThread
    By Eric in forum Mac Programming
    Replies: 11
    Last Post: December 6th, 09:38 PM

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