Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Retreiving a list of available SQL Servers in a new thread.

Posted on 2009-04-09
8
Medium Priority
?
346 Views
Last Modified: 2013-12-17
I use the snippet listed below to get a list of available SQL Server instances.  I would like to find an example of how to execute this in a separate thread so as not have the application appear "frozen".  

Thanks!
DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
ListServers.DisplayMember = "name";
ListServers.ValueMember = "name";
ListServers.DataSource = dt.DefaultView;

Open in new window

0
Comment
Question by:andy_ee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:AUmidh
ID: 24107185
Here is a sample of threading
http://www.yoda.arachsys.com/csharp/threads/
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24107186

System.Threading.Thread.Start
(
new ThreadStart
(delegate
{
DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
ListServers.DisplayMember = "name";
ListServers.ValueMember = "name";
ListServers.DataSource = dt.DefaultView;
 
}
));

Open in new window

0
 
LVL 7

Expert Comment

by:AUmidh
ID: 24107221
From The Web page....

using System;
using System.Threading;

public class Test
{
    static void Main()
    {
        ThreadStart job = new ThreadStart(ThreadJob);
        Thread thread = new Thread(job);
        thread.Start();
       
        for (int i=0; i < 5; i++)
        {
            Console.WriteLine ("Main thread: {0}", i);
            Thread.Sleep(1000);
        }
    }
   
    static void ThreadJob()
    {
        DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
ListServers.DisplayMember = "name";
ListServers.ValueMember = "name";
ListServers.DataSource = dt.DefaultView;
    }
}

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

Author Comment

by:andy_ee
ID: 24113170
@gauthampj

It compiles and runs but the combo box never gets populated
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24113419

System.Threading.Thread.Start
(
new ThreadStart
(delegate
{
DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
ListServers.Invoke(new ThreadStart(delegate
{
ListServers.DisplayMember = "name";
ListServers.ValueMember = "name";
ListServers.DataSource = dt.DefaultView;
}),null);
}
));

Open in new window

0
 

Author Comment

by:andy_ee
ID: 24115963
I get the following error:

An object reference is required for the non-static field, method, or property 'System.Threading.Thread.Start(object)'
public partial class FormSQLServerList : Form
{
    public FormSQLServerList()
    {
        InitializeComponent();
    }
    private void FormSQLServerList_Load(object sender, EventArgs e)
    {
        System.Threading.Thread.Start
        (
        new ThreadStart
        (delegate
        {
            DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
            ListAvailableSQLServers.Invoke(new ThreadStart(delegate
            {
                ListAvailableSQLServers.DisplayMember = "name";
                ListAvailableSQLServers.ValueMember = "name";
                ListAvailableSQLServers.DataSource = dt.DefaultView;
            }), null);
        }
        ));
    }
}

Open in new window

0
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 2000 total points
ID: 24117035

public partial class FormSQLServerList : Form
{
    public FormSQLServerList()
    {
        InitializeComponent();
    }
    private void FormSQLServerList_Load(object sender, EventArgs e)
    {
        System.Threading.Thread t = new
        System.Threading.Thread
        (
        new ThreadStart
        (delegate
        {
            DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
            ListAvailableSQLServers.Invoke(new ThreadStart(delegate
            {
                ListAvailableSQLServers.DisplayMember = "name";
                ListAvailableSQLServers.ValueMember = "name";
                ListAvailableSQLServers.DataSource = dt.DefaultView;
            }), null);
        }
        ));
        t.Start();
    }
}

Open in new window

0
 

Author Closing Comment

by:andy_ee
ID: 31568524
Excellent!  Thanks for all the help!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question