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:
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.
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
-Joseph
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:
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.
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
-Joseph
Last edited: