Novo
New member
- Joined
- Jan 15, 2009
- Messages
- 2
- Programming Experience
- Beginner
Hello Community,
I have to Archive Files with Multithreads and now i have to implement a Statistic function.
Everytime a thread is finished with its work, it sends an Event with zipped Filesize, unzipped Filesize and Filepath to the main class.
There it should count the files, that all threads have done.
i did it this way:
Thread use a stat.ini file with SyncLock (so only one Thread can use it, all other Threads wait, till the first Thread is finished)
read the number, make number+1 and save the file.
The Problem:
it don't count correctly!
What can i do?
i could use SyncLock, Monitor or Invoke required
Mfg Novo
I have to Archive Files with Multithreads and now i have to implement a Statistic function.
Everytime a thread is finished with its work, it sends an Event with zipped Filesize, unzipped Filesize and Filepath to the main class.
There it should count the files, that all threads have done.
i did it this way:
Thread use a stat.ini file with SyncLock (so only one Thread can use it, all other Threads wait, till the first Thread is finished)
read the number, make number+1 and save the file.
The Problem:
it don't count correctly!
What can i do?
i could use SyncLock, Monitor or Invoke required
Mfg Novo
VB.NET:
'Everytime a Thread is finished, to this event
Public Sub NTStatistic(ByVal Dateiname As String, ByVal SizeUnzip As Integer, ByVal SizeZip As Integer)
SyncLock ThreadLock
Dim AnzahlFiles As Long
Dim GezippteDatei As Long
Dim UngezippteDatei As Long
Try
Dim TextAusDatei() As String = File.ReadAllText("stat.ini").Split(Environment.NewLine)
AnzahlFiles = Val(TextAusDatei(0)) + 1
GezippteDatei = Val(TextAusDatei(1)) + SizeZip
UngezippteDatei = Val(TextAusDatei(2)) + SizeUnzip
Catch
'... das erste mal...
AnzahlFiles = 1
GezippteDatei = SizeZip
UngezippteDatei = SizeUnzip
End Try
Dim Message As String = AnzahlFiles & Environment.NewLine _
& GezippteDatei.ToString & Environment.NewLine _
& UngezippteDatei.ToString & Environment.NewLine
Try
File.WriteAllText("stat.ini", Message)
Catch ex As Exception
Try
File.AppendAllText("stat.ini", Message)
Catch er As Exception
Try
File.AppendAllText("stat.ini", Message)
Catch err As Exception
Try
File.AppendAllText("stat.ini", Message)
Catch errr As Exception
Try
File.AppendAllText("stat.ini", Message)
Catch errrr As Exception
End Try
End Try
End Try
End Try
End Try
End SyncLock
End Sub