Re: Getting mouse clicks when the main loop is busy
Re: Getting mouse clicks when the main loop is busy
- Subject: Re: Getting mouse clicks when the main loop is busy
- From: Kyle Sluder <email@hidden>
- Date: Mon, 11 Nov 2013 09:59:41 -0800
> On Nov 10, 2013, at 9:37 PM, Seth Willits <email@hidden> wrote:
>
> On Nov 10, 2013, at 1:14 PM, Kyle Sluder <email@hidden> wrote:
>
>>> On Nov 10, 2013, at 1:06 PM, Charles Srstka <email@hidden> wrote:
>>>
>>> What I usually do is just have NSDocument's readFromData/URL/fileWrapper/etc method not actually do much, and then in windowControllerDidLoadNib: put up a progress bar, and start the loading in a background thread. You can either do this by hiding the main window and displaying the progress bar in a separate window, or by showing the empty document window and putting up a sheet with the progress bar in it while the document window is populated with data.
>>
>> This sounds like a violation of file coordination and NSDocument file-activity rules. You really ought to load your document contents in the initializer.
>
>
> *initializer*?
Shorthand for "initializer or one of the methods called by it, like -readFromFileWrapper:ofType:".
My point is that it takes a lot of work to subvert NSDocument's understanding of when and how a document is loaded, and simply forking off a background operation to load your document is NOT going to play nice with that.
NSDocument invokes -readFromURL:… within a file coordination block. If you bail out of that early and read your document contents in a background operation, you will erroneously yield the document back to whatever reacquirer is waiting for it—whether in your app or another. This can cause corruption as another app believes it has exclusive write access to your document’s contents just as your background op gets around to reading it.
If you instead try to invoke your own file coordination from the background operation, you will very likely deadlock against NSDocument’s own coordinated access.
There is no winning here. Load your document when and where NSDocument expects you to load your document. Enroll in background document loading by returning YES from +canConcurrentlyReadDocumentsOfType:. Put up progress UI before loading the document, and take it down when it’s done.
--Kyle Sluder
_______________________________________________
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