Welcome to Dream.In.Code
Become a VB Expert!

Join 137,228 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,891 people online right now. Registration is fast and FREE... Join Now!




vb.net; threading

 
Reply to this topicStart new topic

vb.net; threading, vb.net; threading

larimore
18 Mar, 2007 - 10:18 PM
Post #1

New D.I.C Head
*

Joined: 18 Mar, 2007
Posts: 11


My Contributions
hello guys,
im doing a project right now that print card number..im doing a check to make sure no 2 card has the same number id...i use threading since its process may contain thousands of card number..problem is, im also calling a global function inside the thread...i get an error evrytime i call it..do you have any suggestion how to solve this..
thanks in advance...
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Vb.net; Threading
18 Mar, 2007 - 10:41 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Please post the code the you are asking about.

It might just be how you are trying to call the global function. Either the parameters you are supplying or perhaps how you are trying to implement the thread. But without seeing the code it will be difficult to tell.
User is offlineProfile CardPM
+Quote Post

larimore
RE: Vb.net; Threading
18 Mar, 2007 - 10:51 PM
Post #3

New D.I.C Head
*

Joined: 18 Mar, 2007
Posts: 11


My Contributions
this is the codes...sorry it might be hrad to read since the lines are quite long


CODE

'this is inside a thread procedure
ReDim Preserve strEdyFile(i)
strEdyFile(i) = strTemp(1)
'check for Distinct Value
bolDistinctEdy = DISTINCTEdy(strEdyFile(i))
If bolDistinctEdy = False Then
       CheckInputData = False
       intTempError += 1 'count error
       ReDim Preserve strTempError(intTempError)
       'saved error in array      
       strTempError(intTempError) = "Error" & strTemp(1)
End If




'in module
'global function region
Public Function DISTINCTEdy(ByVal strEdyNo As String) As Boolean
   Dim streamEdyRead As New StreamReader(cnsCreateFile & "\AllEdy\AllEdy.CSV")
   Dim strTemp() As String
   DISTINCTEdy = True

   Do While streamEdyRead.Peek >= 0
            Dim strOneRow As String = streamEdyRead.ReadLine
            If strOneRow = "" Then
                Exit Do
            End If
            strTemp = strOneRow.Split(",")
            If strEdyNo = strTemp(1) Then
                DISTINCTEdy = False
                Exit Do
            End If
        Loop
        streamEdyRead.Close()  'close stream to write new record
        If DISTINCTEdy = False Then   'double record will not be saved a
            Exit Function
        End If
        Dim streamEdyWrite As New StreamWriter  (cnsCreateFile& "\AllEdy\AllEdy.CSV")
        streamEdyWrite.WriteLine(strEdyNo)    'save all record in
        streamEdyWrite.Close()
End Function

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Vb.net; Threading
18 Mar, 2007 - 10:56 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Sorry I should have mentioned it would be helpful if you post the exact error message, as well. Thx.

What data type is your strEdyFile array?
User is offlineProfile CardPM
+Quote Post

larimore
RE: Vb.net; Threading
18 Mar, 2007 - 11:55 PM
Post #5

New D.I.C Head
*

Joined: 18 Mar, 2007
Posts: 11


My Contributions
biggrin.gif it seems to be working now..i think it might have been because i didnt close some streamreader..
anyway here is the new code... nothing much has change....the error was "The file your accessing is currently being used" (i had to translate that since it was in japanese)....

by the way the strEdyFile is a string...this was the declaration dim strEdyFile() as string....since i dont know
many record each process may contain i used the i integer to count every loop and ReDim the array while preserving the old record...is this a bad practice?...well thanks a lot...

CODE

'this is inside a thread procedure
ReDim Preserve strEdyFile(i)
strEdyFile(i) = strTemp(1)
'check for Distinct Value
bolDistinctEdy = DISTINCTEdy(strEdyFile(i))
If bolDistinctEdy = False Then
       CheckInputData = False
       intTempError += 1 'count error
       ReDim Preserve strTempError(intTempError)
       'saved error in array      
       strTempError(intTempError) = "Error" & strTemp(1)
End If




'in module
'global function region
Public Function DISTINCTEdy(ByVal strEdyNo As String) As Boolean
   Dim streamEdyRead As StreamReader
   Dim strTemp(),strTempFile As String

   strTempFile = cnsCreateFile & "\AllEdy\AllEdy.CSV"   'cnsCreateFile is some global constant
   DISTINCTEdy = True


   Try
            If File.Exists(strTempFile) = True Then
                streamEdyReader = New StreamReader(strTempFile)
                              Do While streamEdyRead.Peek >= 0
            Dim strOneRow As String = streamEdyRead.ReadLine
            If strOneRow = "" Then
                Exit Do
            End If
            strTemp = strOneRow.Split(",")
            If strEdyNo = strTemp(1) Then
                DISTINCTEdy = False
                Exit Do
            End If
        Loop
        streamEdyRead.Close()  'close stream to write new record
            else
                DISTINCTEdy = False
                Exit Try
            end if
    Catch
                DISTINCTEdy = False
    finally
          If DISTINCTEdy = true Then   'double record will not be saved a
    Dim streamEdyWrite As New StreamWriter  (cnsCreateFile& "\AllEdy\AllEdy.CSV")
    streamEdyWrite.WriteLine(strEdyNo)    'save all record in
    streamEdyWrite.Close()
          Endif
    end try
End Function

[/quote]

This post has been edited by larimore: 18 Mar, 2007 - 11:56 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Vb.net; Threading
19 Mar, 2007 - 10:22 AM
Post #6

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
QUOTE
since i dont know
many record each process may contain i used the i integer to count every loop and ReDim the array while preserving the old record...is this a bad practice?...well thanks a lot..


This is exactly why the ReDim statement was created. So to answer your question, no it is not considered bad practice.

QUOTE
The file your accessing is currently being used

With an error message like that the problem is more likely that you had the file open in another application at the same time.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:03PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month