We help IT Professionals succeed at work.

Loading Data Async

Kevin Robinson
on
I am try to load some of my data asynchronously using the code below.   But I am getting the error.

Cross-thread operation not valid: Control 'dg_Contacts' accessed from a thread other than the thread it was created on.
Private M_LoadContactAsync As WCF_Contacts.Contact.DelLoadContact

    Public Sub LoadContactAsync()
        M_LoadContactAsync = AddressOf Me.Contact.LoadContacts
        M_LoadContactAsync.BeginInvoke(Me.M_OrgID, AddressOf CallBackLoadAddress, Nothing)
    End Sub
    Public Sub CallBackLoadAddress(ByVal r As IAsyncResult)
        Me.Contacts = Me.M_LoadContactAsync.EndInvoke(r)
        Me.dg_Contacts.DataSource = Me.Contacts
    End Sub

Open in new window

Comment
Watch Question

Senior .Net Consultant
Top Expert 2016
Commented: