Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacFrameworks Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSOperation
This example is the version from Sun, 17th Mar 2012.
Project "NSOperation.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
dim i as integer
dim nn as MyNSOperationMBS
q=new NSOperationQueueMBS
for i=1 to 16
nn=new MyNSOperationMBS
n.Append nn
q.addOperation nn
next
End EventHandler
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
dim nn as MyNSOperationMBS
if q<>Nil then
if q.areAllOperationsFinished then
me.Mode=0
nn=n(0)
MsgBox str(nn.count)+" -> "+str(nn.result)
end if
end if
End EventHandler
End Control
Property Protected n() As mynsoperationMBS
Property Protected q As nsoperationqueueMBS
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class MyNSOperationMBS Inherits NSOperationMBS
EventHandler Sub Close()
#pragma DisableBackgroundTasks
#pragma DisableAutoWaitCursor
#pragma StackOverflowChecking false
System.DebugLog "Close"
End EventHandler
EventHandler Sub Finished()
#pragma DisableBackgroundTasks
#pragma DisableAutoWaitCursor
#pragma StackOverflowChecking false
System.DebugLog "Finished"
End EventHandler
EventHandler Sub Open()
#pragma DisableBackgroundTasks
#pragma DisableAutoWaitCursor
#pragma StackOverflowChecking false
System.DebugLog "Open"
localdic=new Dictionary
End EventHandler
EventHandler Sub Work()
#pragma DisableBackgroundTasks
#pragma DisableAutoWaitCursor
#pragma StackOverflowChecking false
System.DebugLog "Work"
dim i,n as integer
dim d,x as double
dim w as window1
dim a(-1) as string
count=100000
for i=1 to count
lock // lock RB runtime so we can call it
'// this will crash because of the stack check
'// localdic.value(i)=i
a.append str(i)
unlock
// this does not need locking and wastes CPU time
x=0
for n=1 to 10000
x=x+1
next
d=d+i
next
result=d
System.DebugLog "Work done"
End EventHandler
Property count As integer
Property localdic As dictionary
Property result As double
End Class
End Project
The items on this page are in the following plugins: MBS MacCocoa Plugin.