Updating text boxes during processing in a loop

Hi,
I have a form which has a button that when pressed creates a object. The object has a process() method which carries out some processing which can take some time...

Is it posssible to pass in a procedure name as a arguement to process(procedure_name) method that can be called within the process method each time around a loop to update a form UI to provide the user with processing feedback...??



Thanks Ian


 
LVL 1
ISCAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

computerdoctorserviceCommented:
Have you tried
YourObject.refresh
followed
Application.doevents()
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Yes...technically it's possible.

...but instead of passing IN a delegate that should update the TextBoxes, why not make your "object" Raise a Custom Progress EVENT that the Form can subscribe to with AddHandler()?
0
ISCAuthor Commented:
Hi,

Unfortunately I can not pass the form into the process() function if I could your suggestion would work...

The process() function belongs to a class that is also used by console application so the class can not work with any graphical controls...

Thanks Ian
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

ISCAuthor Commented:
Idle Mind,
"why not make your "object" Raise a Custom Progress EVENT that the Form can subscribe to with AddHandler()?" This sounds good...

Could you write a simple example for me...?  
Regards Ian
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is a simple example that should be useable in either a WinForms or a Console application:
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' for simplicity since you said you would also be doing a similar thing from a Console app
        ' the focus of the example is really down below in Class SomeThing
        Form.CheckForIllegalCrossThreadCalls = False
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim st As New SomeThing
        st.Process(New SomeThing.Progress(AddressOf FeedbackReceived))
    End Sub
 
    Private Sub FeedbackReceived(ByVal value As Integer)
        TextBox1.Text = value
        Application.DoEvents()
    End Sub
 
End Class
 
Public Class SomeThing
 
    Public Delegate Sub Progress(ByVal someValue As Integer)
 
    Public Sub Process(ByVal feedback As Progress)
        For i As Integer = 1 To 10
            System.Threading.Thread.Sleep(1000) ' simulated "work"
            feedback(i)
        Next
    End Sub
 
End Class

Open in new window

0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is the same Class being used in a Console app:
Module Module1
 
    Sub Main()
        Dim st As New SomeThing
        st.Process(New SomeThing.Progress(AddressOf FeedbackReceived))
    End Sub
 
    Private Sub FeedbackReceived(ByVal value As Integer)
        Console.WriteLine(value)
    End Sub
 
End Module
 
Public Class SomeThing
 
    Public Delegate Sub Progress(ByVal someValue As Integer)
 
    Public Sub Process(ByVal feedback As Progress)
        For i As Integer = 1 To 10
            System.Threading.Thread.Sleep(1000) ' simulated "work"
            feedback(i)
        Next
    End Sub
 
End Class

Open in new window

0
Mike TomlinsonMiddle School Assistant TeacherCommented:
The original question did not mention the Console aspect of your problem.  An EVENT based solution is well suited for Console apps...  =\
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
My last statement should actually read:

    An EVENT based solution is *** NOT *** well suited for Console apps...  =\
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ISCAuthor Commented:
Hi,

thansk for this I'll give it a try...

The class is used by both a GUI app and a console app...

Thanks Ian
0
ISCAuthor Commented:
Thanks Idle Mind I managed to get this working...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.