منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : مشروع مفتوح المصدر لنسخ الملفات او عمل نسخة احتياطية بتعدد المسارات
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
استخدام Multithreading في نسخ الملفات

حيث احدى العمليات تقوم بالنسخ والاخرى تظهر اسم الملفات التي يتم نسخها وعملية اخرى تحسب الوقت المتبقى
ملف المشروع بالمرفقات

[صورة مرفقة: Backup.gif]

وهنا نظرة سريعة على المشروع

PHP كود :
Imports System.Threading
Imports System
.IO
Imports System
.Diagnostics.Process 


PHP كود :
Imports System.Windows

Public Class Backup

    
' Declare the FileCopy class.
    ' 
This class will create 3 threads to copycount and mirror files
    
' and raise events for each, so the events must be handled
    ' 
to update the form with status data.
 
   Dim WithEvents CopyFiles As FileCopy

    Private Sub StartCopy_Click
(ByVal sender As System.ObjectAs System.EventArgs_
        Handles StartCopy
.Click

        
' Create the FileCopy class which will initiate the threads
        CopyFiles = New FileCopy

        ' 
Initiate the copycount and mirror threads from the FileCopy class
 
       CopyFiles.StartCopy()

 
   End Sub
    
.
 
   remaining forms code
    
.
End Class 


PHP كود :
Imports System.IO

Public Class FileCopy

    
' Declares the variables you will use to hold your thread objects.
    Public CopyThread As System.Threading.Thread
    Public CountThread As System.Threading.Thread
    Public MirrorThread As System.Threading.Thread

    Public Sub StartCopy()

        ' 
Sets the copy and count threads using the AddressOf the subroutine where
        
' the thread will start.
        CopyThread = New System.Threading.Thread(AddressOf Copy)
        CopyThread.IsBackground = True
        CopyThread.Name = "Copy"
        CopyThread.Start()

        CountThread = New System.Threading.Thread(AddressOf Count)
        CountThread.IsBackground = True
        CountThread.Name = "Count"
        CountThread.Start()

    End Sub
    .
    . code for the rest of the class
    .
End Class 


PHP كود :
Imports System.IO

Public Class FileCopy

    
' Declare the events that will be raised by each thread
    Public Event CopyStatus(ByVal sender As Object, ByVal e As BackupEventArgs)
    Public Event CountStatus(ByVal sender As Object, ByVal e As BackupEventArgs)
    Public Event MirrorStatus(ByVal sender As Object, ByVal e As BackupEventArgs)

    ' 
Declares the variables you will use to hold your thread objects.
 
   Public CopyThread As System.Threading.Thread
    Public CountThread 
As System.Threading.Thread
    Public MirrorThread 
As System.Threading.Thread

    
' Class variables' Class variables
    Private _filePath 
As String
    Private _fileSize 
As String
    Private _copiedFolders 
As Long
    Private _copiedFiles 
As Long
    Private _countedFolders 
As Long
    Private _countedFiles 
As Long
    Private _mirroredFolders 
As Long
    Private _mirroredFiles 
As Long
    
.
 
   even more class variables but we will just show the relevant ones.
 
   .

 
   Public Sub StartCopy()

 
       ' Sets the copy and count threads using the AddressOf the subroutine where
        ' 
the thread will start.
 
       CopyThread = New System.Threading.Thread(AddressOf Copy)
 
       CopyThread.IsBackground True
        CopyThread
.Name "Copy"
 
       CopyThread.Start()

 
       CountThread = New System.Threading.Thread(AddressOf Count)
 
       CountThread.IsBackground True
        CountThread
.Name "Count"
 
       CountThread.Start()

 
   End Sub

     
Private Sub Copy()
 
       .
 
       this is a program loop with logic to copy files
        
.
 
       Loop to Copy Files

            Copy a file here

            
' Raise the copy status event at the end of the program loop
            RaiseEvent CopyStatus(Me, New BackupEventArgs_
                    ("", 0, _copiedFiles, _copiedFolders))
            Threading.Thread.Sleep(1)
        End Loop

      End Sub

      Private Sub Count()
        .
        . this is a program loop with logic to count files
        .
        Loop to Count Files

            Count a file here

            ' 
Raise the count status event at the end of the program loop
            RaiseEvent CountStatus
(Me, New BackupEventArgs_
                    
(""0_countedFiles_countedFolders))
 
           Threading.Thread.Sleep(1)
 
       End Loop

    End Sub
    
.
 
   code for the rest of the class
 
   .
End Class 
جزاك الله خيرا وبارك فيك أخي الفاضل