Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 362599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:15:45+00:00 2026-05-12T13:15:45+00:00

I have a function public void ShowAllFly() { cbFly.Items.Clear(); cbFly.Items.Add(Uçuş Seçiniz…); dsFlyTableAdapters.tblFlyTableAdapter _t=new KTHY.dsFlyTableAdapters.tblFlyTableAdapter();

  • 0

I have a function

public void ShowAllFly()
{  
        cbFly.Items.Clear();
        cbFly.Items.Add("Uçuş Seçiniz...");

        dsFlyTableAdapters.tblFlyTableAdapter _t=new KTHY.dsFlyTableAdapters.tblFlyTableAdapter();
        dsFly _mds = new dsFly();
        _mds.EnforceConstraints = false;
        dsFly.tblFlyDataTable _m = _mds.tblFly;
        _t.Fill(_m);
        foreach (DataRow _row in _m.Rows)
        {
            cbFly.Items.Add(_row["FlyID"].ToString()+"-"+_row["FlyName"].ToString() + "-" + _row["FlyDirection"].ToString() + "-" + _row["FlyDateTime"].ToString());
        }
        _Thread.Abort();
        timer1.Enabled = false;
        WaitPanel.Visible = false;
}

In Form_Load Function Like this;

{
    _Thread = new System.Threading.Thread(new System.Threading.ThreadStart(ShowAllFly));
    _Thread.Start();
    _Thread.Priority = System.Threading.ThreadPriority.Normal;
}

But When I run it;

in ShowAllFly function

cbFly.Items.Clear(); ----  HERE Gives ERROR  LIKE  Control.Invoke must be used to interact with controls created on a separate thread.

What is the problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:15:45+00:00Added an answer on May 12, 2026 at 1:15 pm

    There are two golden rules of threading in Windows Forms:

    • Don’t touch any control properties or methods (other than those explicitly listed as being okay) from any thread other than the one which created the control’s “handle” (usually there’s just one UI thread)
    • Don’t block the UI thread for any significant length of time, or you’ll make the application unresponsive

    In order to interact with the UI from a different thread, you need to “marshall” the call to the UI thread, using a delegate and calling Control.Invoke/BeginInvoke. You can test whether or not you need to call Invoke using the InvokeRequired property, but these days I personally tend to just do it anyway – there’s not much penalty for invoking when you don’t need to.

    Lambda expressions in C# 3 (or anonymous methods in C# 2) make this a lot more pleasant as well.

    For instance, you could use:

    cbFly.Invoke((MethodInvoker)(() => cbFly.Items.Clear()));
    

    All the brackets get in the way a bit, so you might want to add an extension method like this, if you’re using C# 3:

    public static void Invoke(this Control control, MethodInvoker action)
    {
        control.Invoke(action);
    }
    

    Then you could do:

    cbFly.Invoke(() => cbFly.Items.Clear());
    

    which is a good deal simpler. Usually you can get away with using a MethodInvoker by capturing any variables you need to access within the delegate.

    See my threading tutorial or Joe Albahari’s for more details.

    As a secondary matter, I see you’re using Thread.Abort – in fact on your own thread, despite it having other calls after it. Why? Aborting any thread other than your own is an “emergencies only” type call (which should usually be followed by the app being unloaded anyway) and I can’t see any reason to abort the current thread when there’s still work to be done afterwards…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.