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 536157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:47:33+00:00 2026-05-13T09:47:33+00:00

I have a try-catch statement in reference to downloading a file. When the file

  • 0

I have a try-catch statement in reference to downloading a file. When the file is downloaded, I then enable one of my menu items then turn off a timer set to retry the download in one minute.

My problem is that for some reason my trafficManagementToolStripMenuItem.Enabled = true; line is activating the catch statement even though the menu item is being enabled. The file correctly downloads and when I comment out that line, it works perfectly. But every time I run it, I get the “error” message box and the timer is not disabled even though the menu item correctly enables after the download is complete.

Any ideas?

try
{
    ////downloads Data

    string address = "http://website.file.txt";
    string filename = "vsd.txt";
    WebClient client = new WebClient();
    client.DownloadFile(address, filename);
    trafficManagementToolStripMenuItem.Enabled = true;
    timer1.Enabled = false;
}
catch
{
    timer1.Enabled = true;
    MessageBox.Show("error", "test");
}
  • 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-13T09:47:33+00:00Added an answer on May 13, 2026 at 9:47 am

    You don’t say what the exception is, but I’d guess that you’re running your download routine in a background thread, is that right? You can only access controls from the thread that created them: the main UI thread. Accessing a control such as a ToolStripMenuItem from a background thread will cause an exception.

    If this is the case, use the Control.Invoke or Control.BeginInvoke method to run the .Enabled = true call on the ToolStripMenuItem’s thread. To do this, you’ll need a Control (unfortunately ToolStripMenuItem is only a Component). I’ll assume you can get a reference to the containing Form from somewhere. Now you can write this:

    Action enableAction = delegate() { trafficManagementToolStripMenuItem.Enabled = true; }
    form.BeginInvoke(enableAction);
    

    This causes the enableAction to run on the correct UI thread for form.

    • 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.