Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Update Form based on classed Thread Activity

Posted on 2012-04-10
4
Medium Priority
?
134 Views
Last Modified: 2012-04-11
Hi All,

Can someone please tell me how to show information on a winform based on a (classed) thread's progress. What I mean is, the thread executed as a different class and I can't find a relevant code example.

Public Class frmProgress

 Public Sub doQueue(maxConcurrentThreads As Integer)
        ThreadPool.SetMaxThreads(maxConcurrentThreads, maxConcurrentThreads)
        Dim i As Integer = 0
        Dim max As Integer = lines.Count
        While i < (max)
            Dim caller As New SingleThreadCaller(lines(i))
            ThreadPool.QueueUserWorkItem(AddressOf caller.SingleThreadDoer)
            i = i + 1
        End While
    End Sub

End Class

Public Class SingleThreadCaller

 Public Sub New(DRow As Object)
        Me.rowData = DRow
    End Sub

Public Sub SingleThreadDoer()
        Dim s As String = Me.buildString
        If s <> "" Then
            'Then do start query
            'HELP HERE PLEASE
            frmProgress.setText("Doing Stuff")
        End If
    End Sub

Public Function buildString()
   'etc
   Return s
End Function

End Class

Open in new window

0
Comment
Question by:PhilMellorDev
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 400 total points
ID: 37827563
Here's a quick example:
Public Class frmProgress

    Public Delegate Sub ProgressUpdate(sender As SingleThreadCaller, status As String)

    Public Sub doQueue(maxConcurrentThreads As Integer)
        ThreadPool.SetMaxThreads(maxConcurrentThreads, maxConcurrentThreads)
        Dim i As Integer = 0
        Dim max As Integer = lines.Count
        While i < (max)
            Dim caller As New SingleThreadCaller(lines(i))
            AddHandler caller.Progress, AddressOf stc_Progress
            ThreadPool.QueueUserWorkItem(AddressOf caller.SingleThreadDoer)
            i = i + 1
        End While
    End Sub

    Private Sub stc_Progress(sender As SingleThreadCaller, status As String)
        If Me.InvokeRequired Then
            Me.BeginInvoke(New ProgressUpdate(AddressOf stc_Progress), New Object() {status})
        Else
            Me.Label1.Text = status
        End If
    End Sub

End Class

Public Class SingleThreadCaller

    Public Event Progress(ByVal sender As SingleThreadCaller, ByVal status As String)

    Public Sub New(DRow As Object)
        Me.rowData = DRow
    End Sub

    Public Sub SingleThreadDoer()
        Dim s As String = Me.buildString
        If s <> "" Then
            'Then do start query

            'HELP HERE PLEASE
            RaiseEvent Progress(Me, "Doing Stuff")
        End If
    End Sub

    Public Function buildString()
        'etc
        Return s
    End Function

End Class

Open in new window

0
 

Author Comment

by:PhilMellorDev
ID: 37827821
Hi Idle_Mind,

It looks right from what I've read, but when I try to execute it I get "TargetParameterCountException was unhandled", but unfortunately "No source available".

Thanks,
Phil
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37828126
Sorry...change:

            Me.BeginInvoke(New ProgressUpdate(AddressOf stc_Progress), New Object() {status})

To:

            Me.BeginInvoke(New ProgressUpdate(AddressOf stc_Progress), New Object() {sender, status})
0
 

Author Comment

by:PhilMellorDev
ID: 37833705
Thanks Idle_Mind! Your solution was exactly what I was looking for!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question