Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So here's what I am trying to do, when you right click in the listbox you will see a list of users with there IP address's, once it grabs all of there information, you are able select there name and in the listbox and it will show there information in the textboxes. Now when there is over 5 clients the application will freeze for a good minute or two if not longer.

[code]

   public void GrabInfo()
        {

            regionTB.Text = geoRegion(bo2IpListBox.FocusedItem.SubItems[1].Text);
            cityTB.Text = geoCity(bo2IpListBox.FocusedItem.SubItems[1].Text);
            zipTB.Text = geoZIP(bo2IpListBox.FocusedItem.SubItems[1].Text);
            ispTB.Text = geoISP(bo2IpListBox.FocusedItem.SubItems[1].Text);
        }
        private void bo2IpListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (connected)//basic bool to make it connected before anything happens
            {
                try
                {
                    progressPanel3.Visible = true;
                    new Thread(() => this.GrabInfo()) { IsBackground = true }.Start();
                    progressPanel3.Visible = false;

                }
                catch { }
            }
        }

[/code]

The error I'm getting 
http://i.imgur.com/NPmYOC3.png

What I have tried:

I tried using a Invoke how i could never get that took work as well.
Posted
Updated 30-Jul-17 21:08pm
Comments
Graeme_Grant 30-Jul-17 6:41am    
"I tried using a Invoke how i could never get that took work as well."

Just re-tested my code and it works fine. Please check that you have implemented it correctly.

"Cross-thread operation error" occurs when you try to update objects on the UI thread from another thread. To resolve, you need to invoke on the UI thread:
C#
// you can define a delegate with the signature you want
public delegate void UpdateControlsDelegate();

public void GrabInfo()
{
    //this method is executed by the background worker
    InvokeUpdateControls();
}

public void InvokeUpdateControls()
{
    if (this.InvokeRequired)
    {
        this.Invoke(new UpdateControlsDelegate(UpdateControls));
    }
    else
    {
        UpdateControls();
    }
}

private void UpdateControls()
{
    // update your controls here
    regionTB.Text = geoRegion(bo2IpListBox.FocusedItem.SubItems[1].Text);
    cityTB.Text = geoCity(bo2IpListBox.FocusedItem.SubItems[1].Text);
    zipTB.Text = geoZIP(bo2IpListBox.FocusedItem.SubItems[1].Text);
    ispTB.Text = geoISP(bo2IpListBox.FocusedItem.SubItems[1].Text);
}
 
Share this answer
 
v2
Unfortunately with this code the tool become unresponsive, But I do appreciate the help. Thank you.

Edit it did work, just took twice as longer which is odd.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900