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

  • SEARCH
  • Home
  • 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 211243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:04:40+00:00 2026-05-11T18:04:40+00:00

Currently, I have something like: public partial class Form1 : Form { delegate void

  • 0

Currently, I have something like:

public partial class Form1 : Form
{
delegate void StringDelegate(string value);

private FTP m_ftp;

public Form1()
{
InitializeComponent();
}

private void connect_Click(object sender, EventArgs e)
{
OnResponse("Connecting");
m_ftp = new FTP(server.Text);
m_ftp.ResponseReceived += new FTPResponseHandler(m_ftp_ResponseReceived);
m_ftp.Connected += new FTPConnectedHandler(m_ftp_Connected);
m_ftp.BeginConnect(user.Text, password.Text);
}

void m_ftp_Connected(FTP source)
{
// when this happens we're ready to send command
OnResponse("Connected.");
}

void m_ftp_ResponseReceived(FTP source, FTPResponse Response)
{
OnResponse(Response.Text);
}

private void OnResponse(string response)
{
if (this.InvokeRequired)
{
this.Invoke(new StringDelegate(OnResponse), new object[] { response } );
return;
}

}

private void getFileList_Click(object sender, EventArgs e)
{
FTPFiles files = m_ftp.EnumFiles();

fileList.Items.Clear();

foreach (FTPFile file in files)
{
fileList.Items.Add( new ListViewItem( new string[] { file.Name, file.Size.ToString() } ));
}

tabs.SelectedIndex = 1;
}

private void upload_Click(object sender, EventArgs e)
{
FileStream stream = File.OpenRead("\\My Documents\\My Pictures\\Waterfall.jpg");
m_ftp.SendFile(stream, "waterfall.jpg");
stream.Close();
}

Which works fine – this example was taken from the samples. However, after a recent re-visit I have a question. In this particular case since OnResponse() function doesn’t update the UI, it seems to serve no purpose here. I removed it (as well as all the calls to it) and it still works like before. Am I missing something?

After reading up more about multi threading with forms, I came to understand that this mechanism (demonstrated in the code above) is there to make sure the UI is responsive.

So in case when we need to say, update a UI element (such as textbox, label etc) we would have OnResponse implemented as follows:

delegate void StringDelegate(string dummy); 
void OnResponse(string dummy)
{
    if(!InvokeRequired)
    {
        button1.Text = dummy; 
     } 
    else 
        Invoke(new StringDelegate(OnResponse),new object[] {enabled}); 
} 

If this function is implemented as:

    delegate void StringDelegate(string dummy); 
    void OnResponse(string dummy)
    {
        if(InvokeRequired)
        {            
            Invoke(new StringDelegate(OnResponse),new object[] {dummy}); 
            return;
        }
    } 

What’s the use to have it at all? Is it absolutely necessary?

And another question: is ftp object running on its own thread here?

  • 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-11T18:04:40+00:00Added an answer on May 11, 2026 at 6:04 pm

    The FTP object is definitely running on its own thread. How do I know? This line:

    m_ftp.BeginConnect(user.Text, password.Text);
    

    This is an asynchronous method. Once you call this, the FTP component will use a thread from the .NET threadpool to do all of the work. This dedicated thread is the one that is used to “raise” the events. Ultimately a “raised event” is just one or more method calls to all of the delegates added to the event invocation list; it is this dedicated thread spun up by the Begin method that calls these methods. This thread is not the same thread as the thread that runs the UI, hence the need for the Invoke calls.

    If you want the FTP component to use the UI thread, you’d use the Connect method instead of the BeginConnect method. This means your events wont work either, nor will your UI respond to interaction – this is completely expected because a thread can only do one thing at a time: it’s either servicing the UI, or executing the FTP code. This is why you need a 2nd thread.

    Make sense?

    -Oisin

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

Sidebar

Ask A Question

Stats

  • Questions 166k
  • Answers 166k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, PriorityQueue has a constructor that allows you to a… May 12, 2026 at 1:24 pm
  • Editorial Team
    Editorial Team added an answer In Java 6, other than adding @SuppressWarnings("unchecked"), I don't think… May 12, 2026 at 1:24 pm
  • Editorial Team
    Editorial Team added an answer got it working - had to put a zoom: 1;… May 12, 2026 at 1:24 pm

Related Questions

In my windows forms applications I have a class that extends a backgroundworker, let's
I have written a function that gets a given number of random records from
I currently have a LINQ query implemented as a method of my DataContext class.
In asp.net mvc, I have been thinking it would be more advantageous to specify

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.