Advertisement

02.24.2008 at 02:57PM PST, ID: 23188953
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.6

Multithreading

Asked by xterminator in Visual Studio, .NET, Microsoft Visual Basic.Net

I have a form that holds a dataset. Ofcourse whithin this dataset are tables.
Now I want to add values (rows) to a table in this dataset.
Singlethreaded this isn't a problem, but the rows (and values) need to be added from another thread.

Also on this form a have a statuslabel and a progressbar that needs to be updated from the thread that fills the table.

How to realize this in a safe & correct way?

The code supplied works perfectly single threaded.
I want to run it in a separate progress as the one where the main form is running in.

Note that I don't have a lot of experience about multithreading.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
Private Sub GetNonPlaylistTracks()
        'Declare variables & create temporary table
        Dim objMainPlaylists As IITPlaylistCollection = objITunes.LibrarySource.Playlists
        Dim tblPlaylistTracks As DataTable = New DataTable("tblPlaylistTracks")
        Dim intTeller As Integer = 1
        Dim strPlaylists As String = ""
 
        'Call procedure to set items on the main form
        SetMenuItems("GetNonPlaylistTracks Start")
 
        'Clear the datatable
        dsiTunes.Tables("tblOrphins").Clear()
 
        'Create a column in the temporary table
        Dim colTrackID As DataColumn
        colTrackID = New DataColumn
        With colTrackID
            .DataType = System.Type.GetType("System.Int32")
            .ColumnName = "TrackID"
        End With
        tblPlaylistTracks.Columns.Add(colTrackID)
        'Loop through the entire playlists object
        Do Until intTeller = objMainPlaylists.Count
            'Update statuslabel on main form
            lblStatus.Text = "Enumerating playlists... " & intTeller & "/" & objMainPlaylists.Count
            Dim objCurPlaylist As IITPlaylist = objMainPlaylists.Item(intTeller)
            'Find playlists in the playlists object that are only user and not smart playlists
            If objCurPlaylist.Kind = ITPlaylistKind.ITPlaylistKindUser Then
                Dim objUserPlaylist As IITUserPlaylist = objCurPlaylist
                If objUserPlaylist.Smart = False And objUserPlaylist.SpecialKind = ITUserPlaylistSpecialKind.ITUserPlaylistSpecialKindNone Then
                    Dim objPlaylistTracks As IITTrackCollection = objCurPlaylist.Tracks
                    For Each objCurTrack As IITTrack In objPlaylistTracks
                        'Store each track inside this playlist in the temporary table
                        Dim rowPlaylistTrack As DataRow = tblPlaylistTracks.NewRow
                        rowPlaylistTrack("TrackID") = objCurTrack.TrackDatabaseID
                        tblPlaylistTracks.Rows.Add(rowPlaylistTrack)
                    Next
                End If
            End If
            'Increment counter
            intTeller = intTeller + 1
            'Update progressbar on main form
            pgbTotal.Value = (intTeller / objMainPlaylists.Count) * 50
            Application.DoEvents()
        Loop
        'Reset counter
        intTeller = 0
        'Create new dataview of temporary table & sort
        Dim view As DataView = New DataView(tblPlaylistTracks)
        view.Sort = "TrackID"
        'Loop trough the track collection
        For Each objTrack As IITTrack In objTracks
            'Update statuslabel on main form
            lblStatus.Text = "Checking Track No: " & intTeller & "/" & objTracks.Count
            'If the current track is found inside the temporary table, add it to the table inside the dataset on the main form
            If view.Find(objTrack.TrackDatabaseID) = -1 Then
                Dim rowNonPlaylistTrack As DataRow = dsiTunes.Tables("tblOrphins").NewRow
                rowNonPlaylistTrack("ID") = objTrack.TrackDatabaseID
                rowNonPlaylistTrack("Name") = objTrack.Name
                rowNonPlaylistTrack("Album") = objTrack.Album
                rowNonPlaylistTrack("Artist") = objTrack.Artist
                rowNonPlaylistTrack("Size") = Math.Round((objTrack.Size / 1024)) & " KB"
                rowNonPlaylistTrack("Location") = objTrack.Location
                dsiTunes.Tables("tblOrphins").Rows.Add(rowNonPlaylistTrack)
            End If
            'Increment counter
            intTeller = intTeller + 1
            'Update progressbar on main form
            pgbTotal.Value = 50 + ((intTeller / objTracks.Count) * 50)
            Application.DoEvents()
        Next
        'Clear out temporary table
        tblPlaylistTracks.Clear()
        'Call procedure to set items on the main form
        SetMenuItems("GetNonPlaylistTracks Complete")
    End Sub
[+][-]02.25.2008 at 04:59AM PST, ID: 20974800

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.26.2008 at 04:07PM PST, ID: 20990254

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 12:41AM PST, ID: 20992317

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 12:42AM PST, ID: 20992323

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.27.2008 at 01:54AM PST, ID: 20992644

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Studio, .NET, Microsoft Visual Basic.Net
Sign Up Now!
Solution Provided By: xterminator
Participating Experts: 2
Solution Grade: B
 
 
[+][-]02.27.2008 at 02:17AM PST, ID: 20992745

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 06:25PM PST, ID: 21010207

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628