public class FileCopy : IDisposable
Public Class FileCopy
Implements IDisposable
Dim instance As FileCopy
public ref class FileCopy : IDisposable
type FileCopy =
class
interface IDisposable
end
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
Public Class Form1 : Inherits Form
Friend WithEvents FileCopier As FileCopy
Private fileCopyCancelToken As CancellationTokenSource
Private Sub Button1_Click() Handles Button1.Click
Me.StartCopy()
End Sub
Private Sub Button2_Click() Handles Button2.Click
Me.CancelCopy()
End Sub
Private Sub StartCopy()
' Create a dummy file of 2 GB
Using fs As New FileStream("C:\source file.ext", FileMode.CreateNew)
fs.SetLength(2147483648)
End Using
Me.FileCopier = New FileCopy("C:\source file.ext")
Me.fileCopyCancelToken =
Me.FileCopier.CopyTo("C:\Target file.ext",
bufferSize:=(CInt(Me.FileCopier.File.Length \ (1024 * 100)) + 1),
overwrite:=True,
deleteFileOnCancel:=False,
cancelCallback:=AddressOf Me.FileCopier_CancelCallBack)
End Sub
Private Sub CancelCopy()
' Cancel the current file-copy operation.
Me.FileCopier.CancelCopy(Me.fileCopyCancelToken)
End Sub
''' <summary>
''' Callback that is called when the a file-copy operation of the <see cref="FileCopier"/> is canceled.
''' </summary>
Private Sub FileCopier_CancelCallBack()
Me.Invoke(
Sub()
Me.Label1.Text = "Canceled!"
Me.Label2.Text = "Canceled!"
Me.Label3.Text = "Canceled!"
Me.Label4.Text = "Canceled!"
End Sub)
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Handles the <see cref="FileCopy.FileCopyProgressChanged"/> event of the <see cref="FileCopier"/> instance.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="sender">
''' The source of the event.
''' </param>
'''
''' <param name="e">
''' The <see cref="FileCopyProgressChangedEventArgs"/> instance containing the event data.
''' </param>
''' ----------------------------------------------------------------------------------------------------
Private Sub FileCopier_FileCopyProgressChanged(ByVal sender As Object, ByVal e As FileCopyProgressChangedEventArgs) _
Handles FileCopier.FileCopyProgressChanged
Me.Invoke(
Sub()
Me.Label1.Text = String.Format("Size: {0} MB", (e.Filesize / 1024).ToString("n2"))
Me.Label2.Text = String.Format("Written: {0} MB", (e.BytesRead / 1024).ToString("n2"))
Me.Label3.Text = String.Format("Read: {0} MB", (e.BytesRemaining / 1024).ToString("n2"))
Me.Label4.Text = String.Format("Done: {0}%", e.Percentage.ToString("n2"))
End Sub)
End Sub
End Class
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
FileCopy(FileInfo) | Initializes a new instance of the FileCopy class. |
FileCopy(String) | Initializes a new instance of the FileCopy class. |
File | Gets the source file. |
CancelCopy | Cancels a file-copy operation. |
CopyTo | Asynchronously copies the source file to the specified destination. |
Dispose | Releases all the resources used by this instance. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
IsCanceled | Determines whether the specified file-copy task was cancelled. |
ToString | Returns a string that represents the current object. (Inherited from Object) |
FileCopyProgressChanged | Occurs when the progress of a file-copy operation has changed. |
CanConvertTo |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
CanConvertToT |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, an exception is thrown.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, returns the specified default value.
(Defined by ObjectExtensions) |
IsDisposable |
Determines whether the specified object is a disposable type
(i.e., it implements IDisposable interface).
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
ThrowIfNullTException |
Throws the specified exception if the source object is null.
(Defined by ObjectExtensions) |