Re: NSThread - plz help!!!
Re: NSThread - plz help!!!
- Subject: Re: NSThread - plz help!!!
- From: Esteban <email@hidden>
- Date: Wed, 6 Mar 2002 17:38:48 -0800
All you need to do is spawn off a method into its own thread using
[NSThread detachNewThreadSelector:] (see NSThread docs under Foundation
docs)
Remember to create an NSAutoreleasePool inside this method before you do
anything else in the method and to release the autoreleasepool at the
end.
Within this method you should call a method in the main Application
thread that calls [table reloadData];
You should not try calling any AppKit class methods within a thread
that's not the main thread, because most AppKit class methods are not
thread-safe.
So your code more or less should be something like.
- (void) setupSearch:
{
...
[NSThread detachNewThreadSelector:@selector(searchForFiles:)
toTarget:self withObject:searchData];
...
}
- (void) searchForFiles:(id)searchData
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
...
while(pname = [direnum nextObject])
{
if([[[direnum fileAttributes] fileType]
isEqualToString:NSFileTypeRegular])
{
...
//[table reloadData]; this line is not thread safe
[self update]; //update is in main application thread.
...
}
}
[pool release];
}
- (void) update
{
...
[table reloadData];
...
}
Wednesday, March 6, 2002, at 03:11 PM, Lukasz Kuczborski wrote:
>
i have such a while loop:
>
>
while(pname = [direnum nextObject])
>
{
>
if([[[direnum fileAttributes] fileType]
>
isEqualToString:NSFileTypeRegular])
>
{
>
Table *nowy = [[Table alloc] init];
>
[nowy setIconCell:[[NSWorkspace sharedWorkspace]
>
iconForFile:[fullPath stringByAppendingPathComponent:pname]]];
>
[nowy setPathToFile:[fullPath
>
stringByAppendingPathComponent:pname]];
>
[nowy setFileExtension:[pname pathExtension]];
>
[nowy setFileName:[pname lastPathComponent]];
>
[fileSpecs addObject:nowy];
>
[nowy release];
>
[table reloadData]; =====>>>>> *****i want this operation
>
(reloading TableView) to be threaded (NSThread class), so i could view
>
files
>
in my table one by one till next file is found during the
>
searching....PLEASE HELP...this is really important!!!*****
>
}
>
}
>
>
TIA
>
>
Lukasz
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.