Problem with MutliThreading....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • john20
    New Member
    • Jul 2008
    • 37

    Problem with MutliThreading....

    Hi All,

    I am creating windows application in vb.net and I have problem related to multiple threading. Let me describe you the scenario and what are the problems I am facing.

    On form Load I am creating the thread the calling the relevant methods.

    like below:

    Code:
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    	Dim objThread As System.Threading.Thread		  
    	Dim i as integer
    	
       For i=0 to 4
    
                    
                    objThread = New Thread(AddressOf _startExtractThread)
                    objThread.Start()
                    
       Next
    
    
     End Sub
    Here in this method I am creating one sTempName variable and then I pass that variable as the Name of file and temporary tables to other methods.

    Code:
     Public Sub _startExtractThread()
    
     	dim sTempName as string = "Temp_" & Format(Date.Now, "yyMMdd_HHmmss")
    
       	''Now this variable I am passing to other methods for different task.
    
            ''Below method will create temporary table
       
             getDMTableSchema(objlistCollection, sTempName, sLogFile)
             
            
      	''I am inserting records in this table so in that also i will pass the same variable name
    
            InsertRecords(sTempName,sUserID, sUserPermID, sGroupID, sLogFile) 
    
    	'then I am writing those records in to the CSV file, so for creating csv file again I am passing this sTempName variable
    
    	writeRecords(sTempName,sExportFolder)
    
    		
    	'then I am deleting the temporary created table
    
            sLogSQL = "drop table " & sTempName
            iSuccess = dbExecuteSQL(sLogSQL, sLogFile)	
    	
    
     End Sub
    In the above scenario what I want is if 4 thread are getting created then it should create 4 temporary table and 4 CSV files with different names.

    after that all the 4 temporary table should be dropped.

    But at the movement it is creating only 1 table and 1 csv file and repeating the records in the csv which it retireve from the table.

    Please shed some light and give some idea and hint.

    Many Thanks
    -John
  • john20
    New Member
    • Jul 2008
    • 37

    #2
    Hello Experts,

    Could someone please shed some light on this problem who is expert and have good knowledge in Threading.

    Please give some hint or work around on this problem.

    Thanks
    -John

    Comment

    • R MacDonald
      New Member
      • Mar 2011
      • 24

      #3
      Hello, John,

      The Thread.Start method can take a parameter that will be passed to the routine being started. For example, you could pass in the value of your loop iterator (that is "i") and use this to modify the names of the temporary tables and CSV files.

      Cheers,
      Randy

      Comment

      Working...