Re: NSTextView won't update via NSThread
Re: NSTextView won't update via NSThread
- Subject: Re: NSTextView won't update via NSThread
- From: Dalton Hamilton <email@hidden>
- Date: Fri, 06 Nov 2009 16:50:35 -0500
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:
This email sent to email@hidden