in Education by
So I have some code which copies files to 5 remote PCs on the network. I have a class which impersonates the methods who logon is required ''' ''' Returns the names of the files including their path that match the regex pattern found in this directory. ''' ''' ''' The parameter option SearchOption.AllDirectories indicates that the search should include the current directory and any subdirectories ''' The parameter option SearchOption.TopDirectoryOnly indicates that the search should only include the current directory. ''' Public Function GetFileContent(filePath As String, searchPattern As String, Optional searchOption As SearchOption = Nothing) As String() Implements IEPMADirectoryAccess.GetFileContent If searchOption = Nothing Then searchOption = SearchOption.TopDirectoryOnly End If LogonUser(UserName, Domain, Password, LogonType.LOGON32_LOGON_NEW_CREDENTIALS, 0, UserToken) Using WindowsIdentity.Impersonate(UserToken) Return Directory.GetFiles(filePath, searchPattern, searchOption) End Using End Function ''' ''' Get the name of the Ward from the directory of the current file path ''' Public Function GetWardName(filePath As String) As String Implements IEPMADirectoryAccess.GetWardName LogonUser(UserName, Domain, Password, LogonType.LOGON32_LOGON_NEW_CREDENTIALS, 0, UserToken) Using WindowsIdentity.Impersonate(UserToken) Return New DirectoryInfo(Path.GetDirectoryName(filePath)).Name End Using End Function ''' ''' Creates a directory for the given path ''' Public Sub CreateDirectory(directoryPath As String) Implements IEPMADirectoryAccess.CreateDirectory LogonUser(UserName, Domain, Password, LogonType.LOGON32_LOGON_NEW_CREDENTIALS, 0, UserToken) Using WindowsIdentity.Impersonate(UserToken) Directory.CreateDirectory(directoryPath) End Using End Sub ''' ''' Deletes a file from the specified path ''' Public Sub DeleteFile(filePath As String) Implements IEPMADirectoryAccess.DeleteFile LogonUser(UserName, Domain, Password, LogonType.LOGON32_LOGON_NEW_CREDENTIALS, 0, UserToken) Using WindowsIdentity.Impersonate(UserToken) File.Delete(filePath) End Using End Sub ''' ''' Copies a file from the source path to the destination path ''' Public Sub CopyFile(sourceFilePath As String, destFilePath As String, overwrite As Boolean) Implements IEPMADirectoryAccess.CopyFile LogonUser(UserName, Domain, Password, LogonType.LOGON32_LOGON_NEW_CREDENTIALS, 0, UserToken) Using WindowsIdentity.Impersonate(UserToken) File.Copy(sourceFilePath, destFilePath, overwrite) End Using End Sub part of the code in the parallel loop looks like this: 'If PC is switched on If IsOnline(device.PCName) Then 'For each PC of the ward, get the corresponding folder path targetPath = "\\" + device.PCName + "\c$Report P\" 'Requires access to the network share If Not Directory.Exists(targetPath) Then DirectoryAccess.CreateDirectory(targetPath) End If 'Requires access to the network share For Each fileName As String In DirectoryAccess.GetFileContent(targetPath, "*.pdf") 'Purge (Delete) previous versions of this file in the destination folder Dim fileConst As String fileConst = arr(1) If fileName.Contains(fileConst) Then 'Requires access to the network share DirectoryAccess.DeleteFile(fileName) End If Next DirectoryAccess.CopyFile(f, Path.Combine(targetPath, Path.GetFileName(f), True) End If In the main module I am timing the difference in copying the files when using a normal for loop compared to a parallel for loop but with the same code content within the for loops: enter image description here Initially, the parallel copying is 18 seconds but then becomes 2.82 seconds for the second run. enter image description here The third run is 1.81 seconds. I have checked that the using blocks for impersonation have correctly disposed and reverted to my original credentials after exiting the using block. I am not sure why it is slow in the first run but then speeds up? Could it be that initially the four PCs are inactive, so the process of copying activates them but takes longer? I have an IsOnline function that checks if the PCs are powered on, if not I just skip them to ensure it doesn't slow down the process. enter image description here JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Turns out it was slow because time was measured on different number of pcs on at any one time. Some PCs went to sleep during the measurement so affected the processing time

Related questions

0 votes
    Chapattis made from wheat only swell up but bread becomes spongy, soft and easy to digest. Why is ... ,Science proposed by,electromagnetic theory engineering physics,Science nptel...
asked Nov 7, 2021 in Education by JackTerrance
0 votes
    I am new in software testing and looking to enhance my knowledge. I want to know in detail about: What is ... answer here. Thanks! Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Two trains 140 m and 160 m long run at the speed of 60 km/hr and 40 km/hr respectively in opposite directions on parallel tracks. The time ... sec B. 9.5 sec C. 7.4 sec D. 8.9 sec...
asked Feb 19, 2021 in Education by JackTerrance
0 votes
    How is C 14 C produced in nature and what happens to it subsequently? Give equations for these processes. Select the correct answer from above options...
asked Jan 2, 2022 in Education by JackTerrance
0 votes
    I have an EC2 instance (medium, us-east-1d), and RDS instance (us-east-1a, db.t2.medium). I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 3, 2022 in Education by JackTerrance
0 votes
    In some cases, it is found that a large number of colliding molecules have energy more than thereshold value, yet the ... is slow. Why? Select the correct answer from above options...
asked Jan 4, 2022 in Education by JackTerrance
0 votes
    ________ performs class prediction based on microarray data and clinical parameters (a) M3 (b) M2 (c) MAclinical ... of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    A coin is tossed. If a head comes up, a die is thrown, but if a tail comes up, the coin is tossed again. ... a head and an even number. Select the correct answer from above options...
asked Nov 16, 2021 in Education by JackTerrance
+1 vote
    Which connection configuration offers faster speeds, higher security, lower latencies and higher reliability?...
asked Oct 20, 2020 in Technology by JackTerrance
+1 vote
    Which connection configuration offers faster speeds, higher security, lower latencies and higher reliability?...
asked Oct 20, 2020 in Technology by JackTerrance
0 votes
    def main(): for i in xrange(10**8): pass main() This piece of code in Python runs in (Note: The timing is ... sys 0m0.012s Why is this? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    How can you run multiple Jobs in parallel within Talend?...
asked Mar 23, 2021 in Technology by JackTerrance
...