Results 1 to 1 of 1

Thread: threads in vb.net 2005

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    1

    threads in vb.net 2005

    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:
    1. Imports System.IO
    2. Imports System.Math
    3.  
    4. Public Class Form1
    5.     Public namaFile As String = "C:\sementara.txt"
    6.     Public data1(100) As Double
    7.     Public jumData As Short
    8.     Private i As Short = 0
    9.     Private k As Integer = 0
    10.     Private threadProgress As System.Threading.Thread
    11.     Dim InputNamaFile As StreamWriter
    12.  
    13.     Private Sub OkToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OkToolStripMenuItem.Click
    14.         InputNamaFile = New StreamWriter(namaFile, False)
    15.         jumData = 100
    16.         InputNamaFile.Close()
    17.         Timer1.Enabled = True
    18.     End Sub
    19.  
    20.     Public Sub saveFile1()
    21.         InputNamaFile = New StreamWriter(namaFile, True)
    22.         Dim a As String
    23.         For i = 0 To jumData - 1
    24.             a = CStr(data1(i)) & ";" & CStr(data1(i))
    25.             InputNamaFile.Write(a & vbNewLine)
    26.         Next
    27.         InputNamaFile.Close()
    28.         OnFinished()
    29.     End Sub
    30.  
    31.     Private Sub OnFinished()
    32.         threadProgress = Nothing
    33.     End Sub
    34.  
    35.     Private Sub ProcesDong1()
    36.         threadProgress = New System.Threading.Thread(AddressOf saveFile1)
    37.         'threadProgress.Name = "Background Thread"
    38.         'threadProgress.IsBackground = True
    39.         threadProgress.Start()
    40.     End Sub
    41.  
    42.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    43.         Label1.Text = k
    44.         data1(i) = k
    45.  
    46.         If i <= jumData - 1 Then
    47.             data1(i) = k
    48.         ElseIf i = jumData Then
    49.             ProcesDong1()
    50.             'saveFile1()
    51.             i = -1
    52.         End If
    53.  
    54.         If k = 210 Then
    55.             Timer1.Enabled = False
    56.         End If
    57.  
    58.         i = i + 1
    59.         k = k + 1
    60.     End Sub
    61. End Class
    Attached Files Attached Files
    Last edited by penagate; Aug 7th, 2007 at 07:48 AM. Reason: added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width