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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:19:35+00:00 2026-06-18T10:19:35+00:00

I am writing a small forms based application to connect to an LDAP server,

  • 0

I am writing a small forms based application to connect to an LDAP server, and I wanted the “connect” button to work in the background. So I was following the information and discussion
here

but for whatever reason my code doesn’t appear to be working right: I set a breakpoint at ‘worker.RunWorkerAsync();’ And it just steps right through it.

What am I doing wrong? I am working in Visual Studio 2010, in case it matters.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.DirectoryServices;
using System.Threading;

namespace ldapconnect
{


public partial class Form1 : Form
{
    private void Form1_Load(object sender, EventArgs e)
    {

    }

    public Form1()
    {
        InitializeComponent();
    }

    //server
    public string lds;
    //naming context
    public string root;

    public string username;
    public string password;

    BackgroundWorker worker = new BackgroundWorker();

    private void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        worker = sender as BackgroundWorker;
        foreach (string s in connect(worker, e, lds + "/" + root, txt_user.Text.ToString(), txt_pass.Text.ToString()))
        {
            rtb_results.Text += s + "\r\n";
        }
    }

    private List<string> connect(BackgroundWorker worker, DoWorkEventArgs e, String serv, string usr, string pass)
    {
        //Directory search code taking server path and creds passed in from form
        DirectoryEntry conn = new DirectoryEntry(serv, usr, pass);
        DirectorySearcher ds = new DirectorySearcher(conn);

        //I only want users
        ds.Filter = "objectClass=user";

        List<string> sendBack = new List<string>();

        try
        {
            SearchResultCollection results = ds.FindAll();

            foreach (SearchResult result in results)
            {
                sendBack.Add(result.ToString());                    
            }                
        }
        catch (Exception ex)
        {
            sendBack.Clear();
            sendBack.Add(ex.ToString());
        }

        return sendBack;
    }

    //connect button start background worker
    private void btn_connect_Click(object sender, EventArgs e)
    {
        worker.RunWorkerAsync();
    }

    //Exit Button
    private void btn_close_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    //set server path
    private void btn_server_Click(object sender, EventArgs e)
    {
        string serv = inputBox("ldap://", "IP or DNS Name of LDS Server", "");
        lds = serv;
        lbl_server.Text = lds;
    }

    //set default context
    private void btn_context_Click(object sender, EventArgs e)
    {
        string cntx = inputBox("In CN=,DC=,DC= Form:", "Default Naming Context", "");
        root = cntx;
        lbl_cntx.Text = root;
    }

    //VB interaction box
    private string inputBox(string a,string b,string c)
    {
        return Microsoft.VisualBasic.Interaction.InputBox(a, b, c);
    }

    private void btn_Defaults_Click(object sender, EventArgs e)
    {
        lds = "LDAP://127.0.0.1";
        root = "DC=USERS,DC=TEST,DC=LOCAL";
        txt_user.Text = "reader";
        txt_pass.Text = "password";
        lbl_server.Text = lds;
        lbl_cntx.Text = root;
    }
}
}
  • 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-06-18T10:19:37+00:00Added an answer on June 18, 2026 at 10:19 am

    You are never wiring up the event.

       public Form1()
        {
            InitializeComponent();
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a small RMI based Chat application. The idea is: the Client registers
I'm writing a windows forms application to be sold to small to mid-size corporations
I am writing a small Windows Forms application in C#. Basically, it will ask
I am new to C#. I am writing a small desktop form based application
I'm writing small XMPP server using boost::asio and I want to unit-test my code.
I have an application where I am reading and writing small blocks of data
Coming from a PHP background, I'm used to writing small functions that return a
I'm writing a small Windows application in Visual C++ without MVC. Its really small,
I am writing a small e-shop application with Symfony 2 and I need some
I'm writing a small web server, and having a problem with parsing a request.

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.