Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update Form based on classed Thread Activity

Posted on 2012-04-10
4
Medium Priority
?
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

715 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