Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!pyramid!voder!apple!goldman From: goldman@apple.UUCP (Phil Goldman) Newsgroups: comp.sys.mac Subject: Re: MultiFinder programming tip Message-ID: <6907@apple.UUCP> Date: Sat, 5-Dec-87 14:04:19 EST Article-I.D.: apple.6907 Posted: Sat Dec 5 14:04:19 1987 Date-Received: Thu, 10-Dec-87 19:57:47 EST References: <6897@apple.UUCP> <7838@prls.UUCP> Reply-To: goldman@apple.UUCP (Phil Goldman) Organization: Apple Computer Inc., Cupertino, USA Lines: 33 In article <7838@prls.UUCP> gardner@prls.UUCP (Robert Gardner) writes: >In article <6897@apple.UUCP> han@apple.UUCP (Byron Han) writes: >>A tip for MultiFinder friendly programming. > >>Whenever you call GetNextEvent/WaitNextEvent, you should ALWAYS be >>prepared to handle updates and also suspends/resumes. ALWAYS. > >This sounds like a Multifinder bug. It also sounds like a pain. > It is not a MultiFinder bug, but it is a pain. It is not quite true that you have to always be prepared to handle update events. For example, if you are in the foreground in the middle of some high priority mouse tracking code, you might want to only look for mouse events. The key is to handle update events in a timely fashion while in the background (i.e. not the frontmost layer). MultiFinder will stop feeding an app in the background update events after a certain large number go by without it updating. It is simply to costly on the system to run through this app over and over. You have to always be prepared to handle suspend/resumes because they only have meaning at that exact _WaitNextEvent/_GetNextEvent/_EventAvail call. It would make no sense at all (and would probably cause problems in most apps) to receive a suspend event after you've already been switched back into -- Whatever you needed to do in response to the event it's already too late for. It is difficult in some cases to always handle suspend/resume, but it becomes very simple if you guarantee that you only call _WaitNextEvent/_GetNextEvent /_EventAvail from one routine in your program, and just let this routine handle suspend/resume itself. Then, if you have multiple event loops let each call the routine instead of the _WNE/_GNE/_EvAvail traps themselves. -Phil Goldman Apple Computer