473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

threads vb.net

1
Im fairly new to programming so you will have to excuse my lack of knowledge and experience.
I am trying to find a way of reading from a database using threads. That is a database with say 1000000 rows and i want to be able to use say 5-10 threads to each read a set amount of rows within the database.
Although this may not be practical? Would anybody be able to advise as to the best way to go about this or just the theory behind it, or perhaps even a little code..............
Jul 19 '07 #1
4 2325
Just subscribing, to see what is said. I am doing the EXACT same thing right now. lol

Cyberdaemon
Jul 19 '07 #2
right now my problem is:

A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll

I can't find where the exception is being thrown. I have try statements all over my code and they return nothing...makes me sad. If any one has any ideas where to start looking. Any and all help would be appriciated! Thanks in advance.

Cyberdaemon
Jul 19 '07 #3
TRScheel
638 Expert 512MB
right now my problem is:

A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll

I can't find where the exception is being thrown. I have try statements all over my code and they return nothing...makes me sad. If any one has any ideas where to start looking. Any and all help would be appriciated! Thanks in advance.

Cyberdaemon
How big is your code and could you post it here?
Jul 19 '07 #4
How big is your code and could you post it here?
Expand|Select|Wrap|Line Numbers
  1. Private Shared Sub btnPullData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPullData.Click
  2.         ''__IsLoaded()
  3.  
  4.         Dim OnBaseAdapt As New SqlClient.SqlDataAdapter("", My.Settings.connectionstring1)
  5.         Dim _Continue As Boolean
  6.  
  7.         Const BatchSize As Integer = 3500
  8.         Dim tmpString As String = ""
  9.  
  10.         ' Create the ID/P data table
  11.         Debug.Print("BATCHSIZE = " & BatchSize.ToString)
  12.         Debug.Print("Filling Onbase information...")
  13.         OnBaseAdapt.SelectCommand.CommandText = "<select logic>"
  14.         OnBaseAdapt.SelectCommand.CommandTimeout = 0
  15.         OnBaseAdapt.SelectCommand.CommandType = CommandType.Text
  16.         OnBaseAdapt.Fill(tblOnBase)
  17.  
  18.         ' Create the adapter for the tracking database
  19.         Dim TKRAdapt As New SqlClient.SqlDataAdapter("<select logic>", My.Settings.ConnectionString2)
  20.         TKRAdapt.SelectCommand.CommandTimeout = 0
  21.         TKRAdapt.SelectCommand.CommandType = CommandType.Text
  22.  
  23.         ' Create the database reader
  24.         Dim TKRReader As SqlClient.SqlDataReader
  25.         Dim tmpBatch As DataTable
  26.  
  27.         ' Create the batches, and let process on individual threads
  28.         TKRAdapt.SelectCommand.Connection.Open()
  29.         TKRReader = TKRAdapt.SelectCommand.ExecuteReader '(CommandBehavior.CloseConnection)
  30.         Debug.Print("Starting the Tracking Process")
  31.         While TKRReader.Read()
  32.  
  33.             ' Create a new batch table
  34.             tmpBatch = New DataTable
  35.             ''''Debug.Print("Expanding Batch Table...")
  36.             For LoopVarC As Integer = 0 To 4
  37.                 tmpBatch.Columns.Add()
  38.             Next
  39.             ' Fill batch with the information from the tkr database at BATCHSIZE records at a time
  40.             ''''Debug.Print("Creating Batch...")
  41.  
  42.             For LoopVarI As Integer = 0 To BatchSize - 1
  43.                 _Continue = TKRReader.HasRows
  44.                 If _Continue = False Then
  45.                     Exit While
  46.                 End If
  47.  
  48.                 TKRReader.Read()
  49.  
  50.                 tmpBatch.Rows.Add()
  51.                 For LoopVarL As Integer = 0 To 4
  52.                     Try
  53.                         tmpBatch.Rows(LoopVarI).Item(LoopVarL) = TKRReader.Item(LoopVarL)
  54.                     Catch ex As InvalidOperationException
  55.                         Exit For
  56.                     End Try
  57.                 Next
  58.  
  59.             Next
  60.  
  61.             ''''Debug.Print("Batch Creation Complete! Starting Thread...")
  62.  
  63.             ' Pass to the processing thread and start again
  64.             Dim ThdAction As New Thread(AddressOf ThreadAction)
  65.             ThdAction.IsBackground = True
  66.             ThdAction.Start(tmpBatch)
  67.             Thread.Sleep(50)
  68.             ''''Debug.Print("Thread Started, Create Next Batch")
  69.         End While
  70.         ''''Debug.Print("All possible Batches Created, wait for processing to complete")
  71.         ' close conneciton
  72.         TKRReader.Close()
  73.         TKRAdapt.SelectCommand.Connection.Close()
  74.     End Sub
  75.  
  76.     Private Shared Sub ThreadAction(ByVal batch As Object)
  77.         Debug.Print(String.Format("{0} thread started", Thread.CurrentThread.ManagedThreadId.ToString))
  78.         ' Create the Logic object
  79.         Dim CVobj As New CVLogic(CType(batch, DataTable))
  80.         Dim ProcessLck As New Object
  81.         Dim UpdateLck As New Object
  82.  
  83.         Dim ST As Date = Date.Now
  84.         ' Process the Data
  85.         SyncLock ProcessLck
  86.             Try
  87.                 Debug.Print(String.Format("{0} : {1}", Thread.CurrentThread.ManagedThreadId.ToString, "Processing the Data @ Thread Action calling logic object"))
  88.                 CVobj.Process()
  89.             Catch ex As InvalidOperationException
  90.                 Debug.Print("cannot process!!")
  91.             End Try
  92.         End SyncLock
  93.         Dim TS As TimeSpan = Date.Now - ST
  94.         Debug.Print("{0} took {1} to complete PROCESS", Thread.CurrentThread.ManagedThreadId.ToString, TS.ToString)
  95.         Thread.Sleep(50)
  96.  
  97.         ' Update the data
  98.         SyncLock UpdateLck
  99.             ''''''Debug.Print(String.Format("{0} : {1}", Thread.CurrentThread.ManagedThreadId.ToString, "Updating the Data @ Thread Action calling logic object"))
  100.             CVobj.Update()
  101.         End SyncLock
  102.         Thread.Sleep(50)
  103.         Thread.CurrentThread.Abort()
  104.     End Sub
  105.  
  106.  
  107. End Class
  108.  
  109. Public Class CVLogic
  110.     Public tbl As DataTable ' Holds the CV read batch
  111.  
  112.     Public Sub New(ByVal batch As DataTable) ' Initialize the internal datatable
  113.         tbl = New DataTable
  114.         tbl = batch
  115.     End Sub
  116.  
  117.     ' Process the Batch
  118.     Public Sub Process()
  119.         Dim BatchProcess As New Object
  120.         Dim TKR, OnB As DataTableReader
  121.         Dim sTRAKitemname As String = ""
  122.  
  123.         ' Generate the table reader
  124.         TKR = tbl.CreateDataReader
  125.  
  126.         ' SEARCH the tables
  127.         SyncLock BatchProcess
  128.             Debug.Print(String.Format("{0}: Starting Process", Thread.CurrentThread.ManagedThreadId.ToString))
  129.             While TKR.Read
  130.                 Try
  131.                     OnB = tblOnBase.CreateDataReader
  132.                 Catch ex As InvalidOperationException
  133.                     Debug.Print(String.Format("{0} : Cannot Get to OnBase data!", Thread.CurrentThread.ManagedThreadId.ToString))
  134.                     Exit While
  135.                 End Try
  136.  
  137.                 sTRAKitemname = String.Format("{0} {1} - {2} - {3}", TKR("column2").ToString, TKR("column3").ToString, ReformatDate(TKR("column4"), True).Trim, TKR("column1").ToString)
  138.                 While OnB.Read
  139.                     ''''Debug.Print(String.Format("{0} <PROCESS> : Reading onbase", Thread.CurrentThread.ManagedThreadId.ToString))
  140.                     If sTRAKitemname.Trim = OnB("itemname").ToString.Trim Then
  141.                         Try
  142.                             If Val(TKR("column5").ToString) = Val(OnB("numberpages").ToString) Then
  143.                                 ''''Debug.Print(String.Format("{0} : LOADED", Thread.CurrentThread.ManagedThreadId.ToString))
  144.                             Else
  145.                                 ''''Debug.Print(String.Format("{0} : PARTIAL", Thread.CurrentThread.ManagedThreadId.ToString))
  146.                             End If
  147.                             Thread.Sleep(10)
  148.                             Exit While
  149.                         Catch ex As InvalidOperationException
  150.                             Debug.Print(String.Format("{0} : Cannot Get to OnBase data!", Thread.CurrentThread.ManagedThreadId.ToString))
  151.                             Exit While
  152.                         End Try
  153.                     End If
  154.                 End While
  155.             End While
  156.         End SyncLock
  157.  
  158.     End Sub
Good luck, it is a mess right now, I plan on cleaning it as well as the rest of the program once functional. My threading knowledge is, limited. Any suggestions would be helpful. Some information omitted due to massive length thus causing clutter. i.e. Selection logic for SQL. If you have ANY questions do not hesitate. Thank you in advance and may the force be with you!

Cyberdaemon
Jul 19 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
0
by: Al Tobey | last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am building with -Dusethreads. With newer Linux...
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
34
by: Kovan Akrei | last post by:
Hi, I would like to know how to reuse an object of a thread (if it is possible) in Csharp? I have the following program: using System; using System.Threading; using System.Collections; ...
3
by: bygandhi | last post by:
Hi - I am writing a service which will check a process and its threads for their state ( alive or dead ). The process has 5 .net managed threads created using thread.start and each have been...
10
by: [Yosi] | last post by:
I would like to know how threads behavior in .NET . When an application create 4 threads for example start all of them, the OS task manager will execute all 4 thread in deterministic order manes,...
6
by: RahimAsif | last post by:
Hi guys, I would like some advice on thread programming using C#. I am writing an application that communicates with a panel over ethernet, collects data and writes it to a file. The way the...
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
10
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
4
by: tdahsu | last post by:
All, I'd appreciate any help. I've got a list of files in a directory, and I'd like to iterate through that list and process each one. Rather than do that serially, I was thinking I should...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.