Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextView won't update via NSThread




On Nov 6, 2009, at 5:09 AM, Ken Thomases wrote:

On Nov 5, 2009, at 6:20 AM, Dalton Hamilton wrote:

Does anyone have any idea why NSTextView won't update when the code is a thread?

Yes, because Cocoa generally doesn't support manipulating the GUI from any thread other than the main thread.


Read through this:
http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/Multithreading/Introduction/Introduction.html

Regards,
Ken



Well, I would think Cocoa would let me manage whether I'm calling it multiple times and just do what I'm asking.
So, I now I'm trying to set an NSLock, then call the worker Thread and put the output into a MutableString. The Thread then UnLocks the NSLock which tells the Main Thread the NSMutableString has data. The main thread calls [NSTextView setString: myMutableString]; and this continues looping through the work items. When all items are done, the NSTextView updates all at once -- nothing displays in the NSTextView until the thread is finished running even though my main program/thread is continually blocking on the LOCK, obtaining the LOCK (when the thread releases it) then updating NSTextView, UNLOCKING, and looping. In general that's what I'm doing. It just isn't working.


Maybe I'm approaching this incorrectly. My HQ company has provided me with a Python Script (closed and proprietary so I can't convert it) that parses Proxy log files in a certain way. I am creating the GUI for it. My GUI points to a LOGFILE directory and I loop through each file doing an NSTask to call the Python script and read an NSPipe Filehandle of the output. I need to display that in the NSTextView. If I use a single thread (or in other words, don't use a thread) the users can't even click the Pause button I have placed there because the app is too busy. If I thread, now the use could update but I can't put the output in the NSTextView.

Surely this can't be this complicated. I've done lots of Cocoa programming -- self taught -- and have never ran across this problem before.

Thank you all for helping me understand this. I did read the page(s) the link refers to above but I can't devise an action/solution from what it is telling me. It just explains how it works. I'm sure it is there and I just don't understand.

Best Regard,
Dalton Hamilton
Chapel Hill, NC

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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/email@hidden

This email sent to email@hidden
References: 
 >NSTextView won't update via NSThread (From: Dalton Hamilton <email@hidden>)
 >Re: NSTextView won't update via NSThread (From: Ken Thomases <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.