Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Win/Windows File Copy Threaded
Function:
Required plugins for this example: MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/Windows File Copy Threaded
This example is the version from Wed, 21th Aug 2012.
Project "Windows File Copy Threaded.rbp"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
EventHandler Sub Open() if not TargetWin32 then MsgBox "This example is for Windows only." quit end if End EventHandler
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() if CheckBox1.Value then thread1.run else test1 end if End EventHandler
End Control
Control PushButton2 Inherits PushButton
ControlInstance PushButton2 Inherits PushButton
EventHandler Sub Action() if CheckBox1.Value then thread2.run else test2 end if End EventHandler
End Control
Control PushButton3 Inherits PushButton
ControlInstance PushButton3 Inherits PushButton
EventHandler Sub Action() if CheckBox1.Value then thread3.run else test3 end if End EventHandler
End Control
Control Label1 Inherits Label
ControlInstance Label1 Inherits Label
End Control
Control ProgressBar1 Inherits ProgressBar
ControlInstance ProgressBar1 Inherits ProgressBar
End Control
Control ProgressWheel1 Inherits ProgressWheel
ControlInstance ProgressWheel1 Inherits ProgressWheel
End Control
Control CheckBox1 Inherits CheckBox
ControlInstance CheckBox1 Inherits CheckBox
End Control
Control Thread1 Inherits Thread
ControlInstance Thread1 Inherits Thread
EventHandler Sub Run() test1 End EventHandler
End Control
Control Thread2 Inherits Thread
ControlInstance Thread2 Inherits Thread
EventHandler Sub Run() test2 End EventHandler
End Control
Control Thread3 Inherits Thread
ControlInstance Thread3 Inherits Thread
EventHandler Sub Run() test3 End EventHandler
End Control
Control Label2 Inherits Label
ControlInstance Label2 Inherits Label
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action() n = n + 1 label2.text = str(n) End EventHandler
End Control
EventHandler Sub Close() dim source as FolderItem dim dest as FolderItem source=SpecialFolder.Desktop.Child("source.txt") dest=SpecialFolder.Desktop.Child("dest.txt") dest.Delete source.delete End EventHandler
EventHandler Sub Open() WriteTestFile End EventHandler
Sub Test1() PushButton1.Enabled = false PushButton2.Enabled = false PushButton3.Enabled = false List.DeleteAllRows dim source as FolderItem dim dest as FolderItem source=SpecialFolder.Desktop.Child("source.txt") dest=SpecialFolder.Desktop.Child("dest.txt") if dest.Exists then dest.Delete list.AddRow "Copy "+source.AbsolutePath+" to "+dest.AbsolutePath dim w as new WindowsFileCopyMBS w.MultiThreaded = CheckBox1.Value if w.CopyFileSimple(source,dest) then List.AddRow "CopyFile: OK" else List.AddRow "CopyFile: Failed" end if PushButton1.Enabled = true PushButton2.Enabled = true PushButton3.Enabled = true End Sub
Sub Test2() PushButton1.Enabled = false PushButton2.Enabled = false PushButton3.Enabled = false List.DeleteAllRows dim source as FolderItem dim dest as FolderItem source=SpecialFolder.Desktop.Child("source.txt") dest=SpecialFolder.Desktop.Child("dest.txt") if dest.Exists then dest.Delete list.AddRow "Copy "+source.AbsolutePath+" to "+dest.AbsolutePath dim w as new MyWinCopy w.MultiThreaded = CheckBox1.Value if w.CopyFileEx(source,dest,0) then List.AddRow "CopyFileEx: OK" else List.AddRow "CopyFileEx: Failed" end if PushButton1.Enabled = true PushButton2.Enabled = true PushButton3.Enabled = true End Sub
Sub Test3() PushButton1.Enabled = false PushButton2.Enabled = false PushButton3.Enabled = false List.DeleteAllRows dim source as FolderItem dim dest as FolderItem source=SpecialFolder.Desktop.Child("source.txt") dest=SpecialFolder.Desktop.Child("dest.txt") if dest.Exists then dest.Delete list.AddRow "Copy "+source.AbsolutePath+" to "+dest.AbsolutePath dim w as new MyWinCopy w.MultiThreaded = CheckBox1.Value w.Parent=self if w.FileOperationCopy(source,dest,0,"Copying files from REALbasic...") then List.AddRow "FileOperationCopy: OK" if w.OperationsAborted then List.AddRow "Operations was aborted." else List.AddRow "Operations was successful." end if else List.AddRow "FileOperationCopy: Failed" end if PushButton1.Enabled = true PushButton2.Enabled = true PushButton3.Enabled = true End Sub
Sub WriteTestFile() dim source as FolderItem source=SpecialFolder.Desktop.Child("source.txt") dim t as BinaryStream = BinaryStream.Create(source, true) t.write "Hello World" // make a big file. So big, that writing it takes 15 seconds dim m as new MemoryBlock(100*1000*1000) dim tt as integer = ticks + 15*60 while ticks<tt t.Write m t.Flush wend t.Write "end" t.Close List.AddRow "testfile created: "+str(source.Length)+" Bytes" End Sub
Property n As Integer
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
Class MyWinCopy Inherits WindowsFileCopyMBS
EventHandler Function Progress(TotalFileSize as int64, TotalBytesTransferred as int64, StreamSize as int64, StreamBytesTransferred as Int64, StreamNumber as integer, Reason as integer) As integer dim p as integer = 100*TotalBytesTransferred/TotalFileSize if p<>last then // reduce number of addrows... MainWindow.List.AddRow "Progress "+str(TotalBytesTransferred)+" of "+str(TotalFileSize)+" = "+Format(TotalBytesTransferred/TotalFileSize,"0%") last = p end if End EventHandler
Property last As Integer
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Win Plugin.




Links
MBS FileMaker blog