?
Solved

Starting threads for my functions

Posted on 2007-03-28
5
Medium Priority
?
237 Views
Last Modified: 2010-04-23
Somewhat continued from
http:/Q_22477954.html

So, in my keyup event, I'm also acquiring the user's email address.  This calls a function (in my module class) that performs an ldap query to obtain that info.

This is how I accomplish it...
 txtTo.Text = FindEmail(txtShare.Text)

So, in order to get this into it's own thread as well, would I simply follow the past instructions, but place the delegate sub in the module?  (I know I could try before I ask, but I'm a bit lazy today)...

May need some guidance on this - it may be as simple as plugging in what I've previously used - so it could be super-easy points for somebody... :^)
0
Comment
Question by:sirbounty
[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
5 Comments
 
LVL 14

Assisted Solution

by:jake072
jake072 earned 200 total points
ID: 18809627
The delegate can be in the module or in the form, but you will have to use it in the form (i.e., Invoke it in the form), because you need to invoke it in the proper thread context :)

Good luck, let me know if you need more help,

Jake
0
 
LVL 67

Author Comment

by:sirbounty
ID: 18809711
I guess I'm wondering how I would use the above...
Presumably I'd have to change it from
txtTo.Text=FindEmail(txtShare.text)
to something else...?
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1800 total points
ID: 18810727
I would place your FindEmail() function in a class that encapsulates a thread for you.  Then make that class raise a custom event with the return data.

This means that you can't do a direct assignment like are doing now but instead have to move to an event based model.

Public Class Form1

    Private Sub foo()
        Dim sc As New SomeClass
        AddHandler sc.SomeEvent, AddressOf ReturnedEmail
        sc.GetEmailAddress(txtShare.text)
    End Sub

    Private Delegate Sub EmailData(ByVal email As String)

    Private Sub ReturnedEmail(ByVal email As String)
        If Me.InvokeRequired() Then
            Me.Invoke(New EmailData(AddressOf ReturnedEmail), New Object() {email})
        Else
            txtTo.Text = email
        End If
    End Sub

    Public Class SomeClass
 
        Public Event SomeEvent(ByVal email As String)

        Private inData As String
        Private T As System.Threading.Thread

        Private Sub GetEmailAddress(ByVal inData As String)
            If T Is Nothing Then
                Me.inData = inData
                T = New System.Threading.Thread(AddressOf GetTheEmail)
                T.Start()
            End If      
        End Sub

        Private Sub GetTheEmail()
            ' get your email address...however YOU do it

            ' this is simulated work...
            System.Threading.Thread.Sleep(3000)

            ' return the result
            RaiseEvent SomeEvent("~~~Echo~~~ " & inData & " ~~~Echo~~~")
        End Sub

    End Class

End Class
0
 
LVL 14

Expert Comment

by:jake072
ID: 18811365
Idle_Mind has illustrated how to use it... Sorry, I was lazy :)

Jake
0
 
LVL 67

Author Comment

by:sirbounty
ID: 18850852
Sorry for the delay IM - hope to try this out shortly...
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 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