• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Simple example of threading
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Simple example of threading


  • Subject: Simple example of threading
  • From: Steve Palmer <email@hidden>
  • Date: Wed, 11 Feb 2004 04:32:05 +0000

As part of building a progress dialog, I need to kick off a thread in
the same class and have that thread communicate back to the class to
update the UI. From reading the Apple docs and other examples, I need
to use NSConnection for this. However the examples given all seem to do
more than what I need. I just need to have a simple way to call just
one function on the main thread in the same class to update the UI -
nothing else.

In the code that is called once the window is displayed, I have:

-(void)windowDidLoad
{
NSPort *port1 = [NSPort port];
NSPort *port2 = [NSPort port];
NSArray *portArray;

kitConnection = [[NSConnection alloc] initWithReceivePort:port1
sendPort:port2];
[kitConnection setRootObject:self];

// Ports switched here.
portArray = [NSArray arrayWithObjects:port2, port1, nil];
[NSThread detachNewThreadSelector:@selector(workerThread:)
toTarget:self withObject:portArray];
}

Here's what I have so far in the workerThread function:

-(void)workerThread:(NSArray *)portArray
{
NSConnection * serverConnection;
serverConnection = [NSConnection
connectionWithReceivePort:[portArray objectAtIndex:0]
sendPort:[portArray objectAtIndex:1]];
...
}

At this point I'm stuck. I want to call:

-(void)updateProgress:(NSString *)progressInfo
progressValue:(int)progressValue
{
...
}

but I'm at loss as how to get from serverConnection to this function.
Any clues?

- Steve
_______________________________________________
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.

  • Follow-Ups:
    • Re: Simple example of threading
      • From: Nick Zitzmann <email@hidden>
    • Re: Simple example of threading
      • From: Andreas Mayer <email@hidden>
  • Prev by Date: NSSearchField with menu and cancel button
  • Next by Date: Re: applicationShouldTerminateAfterLastWindowClosed
  • Previous by thread: Re: NSSearchField with menu and cancel button
  • Next by thread: Re: Simple example of threading
  • Index(es):
    • Date
    • Thread