Hi All,
I'm new in multithreaded programming and I'd like to ask you for help.
I want to develop application which needs to execute reports. I have to use multithreading functionality because execution one of the report can take a lot of time and others can't wait for process to finish.
I'm using external dll to connect to datasource, create session for specified project and then to execute report.
Below is the code I'm using:
In the loop I create and start thread with passed object.
The problem occurs in RefreshCube method.
When first thread tries to init DataSource than I get message that Data Source can't be initialized. I think it's because the second thread in the meantime execute the same method and creates new object of DataSource and the first thread tries to initialize empty object.
The question is how I can make my code to execute reports asynchronusly without this conflict?
Thanks,
Lukasz
I'm new in multithreaded programming and I'd like to ask you for help.
I want to develop application which needs to execute reports. I have to use multithreading functionality because execution one of the report can take a lot of time and others can't wait for process to finish.
I'm using external dll to connect to datasource, create session for specified project and then to execute report.
Below is the code I'm using:
In the loop I create and start thread with passed object.
Code:
Sub Main()
Dim arr(2) As String
Dim arrD(2) As String
arr(1) = "0A9EBE87468B751C3663818889B10D73"
arr(2) = "8AC5B5784154EBD2D585C38BF7F7E673"
arrD(2) = "Project1"
arrD(1) = "Project2"
For i = 1 To 2
Dim myThread As New Threading.Thread(AddressOf RefreshCube)
Dim obj = New CubeData()
obj.ID = arr(i)
obj.DataSourceName = "192.168.0.11"
obj.login = "administrator"
obj.pwd = ""
obj.ProjectName = arrD(i)
myThread.Start(obj)
Next
End sub
When first thread tries to init DataSource than I get message that Data Source can't be initialized. I think it's because the second thread in the meantime execute the same method and creates new object of DataSource and the first thread tries to initialize empty object.
Code:
Sub RefreshCube(Cube As CubeData)
Dim DataSource As DSSDataSource
dim retVal as String
Try
DataSource = New DSSDataSource()
DataSource.Type = EnumDSSDataSourceType.DssDataSourceTypeServer
DataSource.Location = Cube.DataSourceName
DataSource.Mode = EnumDSSConnectionMode.DssConnectionModeServerAccess
DataSource.AuthMode = EnumDSSAuthModes.DssAuthStandard
DataSource.login = Cube.login
DataSource.Passwd = Cube.pwd
DataSource.Init() '<-- problem appears when thread tries to Init Datasorce
'code for creating session and executing report
................................................
Catch ex As Exception
retVal = ex.Message
Console.WriteLine(ex.Message)
End Try
End Sub
Thanks,
Lukasz