Platforms to show: All Mac Windows Linux Cross-Platform
/Util/Largebinarystream Threaded Reading
Required plugins for this example: MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Util/Largebinarystream Threaded Reading
This example is the version from Sun, 17th Mar 2012.
Project "Largebinarystream Threaded Reading.xojo_binary_project"
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class Window1 Inherits Window
Control ProgressWheel1 Inherits ProgressWheel
ControlInstance ProgressWheel1 Inherits ProgressWheel
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action()
dim t as integer = ticks
stream.Yield=False
for i as integer=0 to 31
ProgressBar1.Value=i
ProgressBar1.Refresh
stream.Write data
next
ProgressBar1.Value=32
t=ticks-t
Listbox1.AddRow "Write done in "+Format(t/60,"0.0")+" seconds."
PushButton2.Enabled=true
PushButton4.Enabled=true
End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action()
dim t as integer = ticks
stream.Yield=False
stream.Position=0
dim d as string
for i as integer=0 to 31
ProgressBar1.Value=i
ProgressBar1.Refresh
d = stream.Read(lenb(data))
next
ProgressBar1.Value=32
t=ticks-t
if lenb(d)<>lenb(Data) then
Listbox1.AddRow "Failed to read data"
else
Listbox1.AddRow "Read done in "+Format(t/60,"0.0")+" seconds."
end if
End EventHandler
End Control
Control Listbox1 Inherits Listbox
ControlInstance Listbox1 Inherits Listbox
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action()
dim w as new WriteThread
w.stream=stream
w.data=data
w.run
End EventHandler
End Control
Control PushButton4 Inherits PushButton
ControlInstance PushButton4 Inherits PushButton
EventHandler Sub Action()
dim w as new ReadThread
w.stream=stream
w.data=data
w.run
End EventHandler
End Control
Control ProgressBar1 Inherits ProgressBar
ControlInstance ProgressBar1 Inherits ProgressBar
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
Control StaticText2 Inherits Label
ControlInstance StaticText2 Inherits Label
End Control
EventHandler Sub Close()
if stream<>nil then
stream.Close
end if
End EventHandler
EventHandler Sub Open()
dim f as FolderItem = GetTemporaryFolderItem
stream=f.CreateLargeBinaryStreamMBS("TEXT","ttxt")
if stream=nil then
MsgBox "Failed to create file!"
end if
data=RandomBytesStringMBS(32*1024*1024) // 128 MB
Listbox1.AddRow "Data length: "+str(lenb(data))
End EventHandler
Property data As string
Property stream As LargeBinaryStreamMBS
End Class
Class ReadThread Inherits Thread
EventHandler Sub Run()
dim t as integer = ticks
stream.Yield=true
stream.Position=0
dim d as string
for i as integer=0 to 31
window1.ProgressBar1.Value=i
d = stream.Read(lenb(data))
next
window1.ProgressBar1.Value=32
t=ticks-t
if lenb(d)<>lenb(Data) then
window1.Listbox1.AddRow "Failed to read data"
else
window1.Listbox1.AddRow "Read threaded done in "+Format(t/60,"0.0")+" seconds."
end if
End EventHandler
Property data As string
Property stream As LargeBinaryStreamMBS
End Class
Class WriteThread Inherits Thread
EventHandler Sub Run()
dim t as integer = ticks
stream.Yield=true
for i as integer=0 to 31
window1.ProgressBar1.Value=i
stream.Write data
next
window1.ProgressBar1.Value=32
t=ticks-t
window1.Listbox1.AddRow "Write threaded done in "+Format(t/60,"0.0")+" seconds."
window1.PushButton2.Enabled=true
window1.PushButton4.Enabled=true
End EventHandler
Property data As string
Property stream As LargeBinaryStreamMBS
End Class
End Project
See also:
The items on this page are in the following plugins: MBS Util Plugin.