Hi Guys,
I have a small problem and I have no idea how to fix it.
I am copying files from time to time to my NAS (drive: Y:\) via Console Application which I want to Schedule.
My NAS sometimes goes to sleep (HDD stop spinning) after a period of not using it.
And when I try to copy files and my NAS is "asleep", sometimes the program get an error message.
Now I thought a solution for this problem is to wake up the NAS, so I create a TEMP File (with streamwriter) in the Root of the NAS Drive and then check if the File.Exists, this would wake the NAS up, but I have a strange issue.
See the following output
Attempt 1:
C:\Users\user\AppData\Local\Temp\test>test.exe
Directory to use is : C:\Users\user\AppData\Local\Temp\test
21/11/2017 18:13:19
Checking if Drive Y:\ is online ...
File Y:\tempfile.tmp deleted
21/11/2017 18:13:21
Drive Y:\ is available and online
When looking at my NAS, the drives are still "asleep" but the programma says it has created the file
and afterwards deleted it. All this in a mere 2 seconds, and I can't find a trace of the File (so it actually hasn't created and deleted it)
But Look at attempt 2: (started a couple seconds after attempt 1)
C:\Users\user\AppData\Local\Temp\test>test.exe
Directory to use is : C:\Users\user\AppData\Local\Temp\test
21/11/2017 18:13:26
Checking if Drive Y:\ is online ...
File Y:\tempfile.tmp deleted
21/11/2017 18:13:58
Drive Y:\ is available and online
After finishing this attempt the Drives are "awake" and you see it took 32 Seconds and not as attempt 1 only 2.
And the file was actually created and deleted.
The code I use is:
Thanks for any pointers.
Ps: Not mapping the drive, but just wanna wake up the drive.
I have a small problem and I have no idea how to fix it.
I am copying files from time to time to my NAS (drive: Y:\) via Console Application which I want to Schedule.
My NAS sometimes goes to sleep (HDD stop spinning) after a period of not using it.
And when I try to copy files and my NAS is "asleep", sometimes the program get an error message.
Now I thought a solution for this problem is to wake up the NAS, so I create a TEMP File (with streamwriter) in the Root of the NAS Drive and then check if the File.Exists, this would wake the NAS up, but I have a strange issue.
See the following output
Attempt 1:
C:\Users\user\AppData\Local\Temp\test>test.exe
Directory to use is : C:\Users\user\AppData\Local\Temp\test
21/11/2017 18:13:19
Checking if Drive Y:\ is online ...
File Y:\tempfile.tmp deleted
21/11/2017 18:13:21
Drive Y:\ is available and online
When looking at my NAS, the drives are still "asleep" but the programma says it has created the file
and afterwards deleted it. All this in a mere 2 seconds, and I can't find a trace of the File (so it actually hasn't created and deleted it)
But Look at attempt 2: (started a couple seconds after attempt 1)
C:\Users\user\AppData\Local\Temp\test>test.exe
Directory to use is : C:\Users\user\AppData\Local\Temp\test
21/11/2017 18:13:26
Checking if Drive Y:\ is online ...
File Y:\tempfile.tmp deleted
21/11/2017 18:13:58
Drive Y:\ is available and online
After finishing this attempt the Drives are "awake" and you see it took 32 Seconds and not as attempt 1 only 2.
And the file was actually created and deleted.
The code I use is:
VB.NET:
Dim driveletter as String = "Y:\"
Dim tempfile As String = "tempfile.tmp"
Try
Using sw As StreamWriter = New StreamWriter(driveLetter & tempfile, False)
sw.Write("Dummy File")
sw.Close()
End Using
System.Threading.Thread.Sleep(1500)
If File.Exists(driveLetter & tempfile) Then
File.Delete(driveLetter & tempfile)
Console.WriteLine("File " & driveLetter & tempfile deleted")
Console.WriteLine(Now)
Console.WriteLine("Drive " & driveLetter & " is available and online")
Else
Throw New Exception
End If
Catch e As Exception
Console.WriteLine(e.Message.ToString)
End Try
Thanks for any pointers.
Ps: Not mapping the drive, but just wanna wake up the drive.
Last edited: