dear..
I want to make program with threading (source I'm attached)
this program generate number (with timer) and save data in array.
if length of array is 100, the array will save in file. the contents
of array will replace with new number and generate again from beginning,
and so on.
this program right if I not use threading. but when I use threading,
output file is large. threading not stop when i use to try stop threading
after make file.
when I activated line
threadProgress.Name = "Background Thread"
threadProgress.IsBackground = True
this program is error.
can you help me ??
this is copy of my scripts
VB.NET Code:
Imports System.IO
Imports System.Math
Public Class Form1
Public namaFile As String = "C:\sementara.txt"
Public data1(100) As Double
Public jumData As Short
Private i As Short = 0
Private k As Integer = 0
Private threadProgress As System.Threading.Thread
Dim InputNamaFile As StreamWriter
Private Sub OkToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OkToolStripMenuItem.Click
InputNamaFile = New StreamWriter(namaFile, False)
jumData = 100
InputNamaFile.Close()
Timer1.Enabled = True
End Sub
Public Sub saveFile1()
InputNamaFile = New StreamWriter(namaFile, True)
Dim a As String
For i = 0 To jumData - 1
a = CStr(data1(i)) & ";" & CStr(data1(i))
InputNamaFile.Write(a & vbNewLine)
Next
InputNamaFile.Close()
OnFinished()
End Sub
Private Sub OnFinished()
threadProgress = Nothing
End Sub
Private Sub ProcesDong1()
threadProgress = New System.Threading.Thread(AddressOf saveFile1)
'threadProgress.Name = "Background Thread"
'threadProgress.IsBackground = True
threadProgress.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Text = k
data1(i) = k
If i <= jumData - 1 Then
data1(i) = k
ElseIf i = jumData Then
ProcesDong1()
'saveFile1()
i = -1
End If
If k = 210 Then
Timer1.Enabled = False
End If
i = i + 1
k = k + 1
End Sub
End Class
Last edited by penagate; Aug 7th, 2007 at 07:48 AM.
Reason: added code tags