Click here to Skip to main content
15,897,891 members
Home / Discussions / C#
   

C#

 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 10:27
Jacob Dixon12-Apr-10 10:27 
GeneralRe: Stopping threads (semi-safely).... Pin
Luc Pattyn12-Apr-10 10:55
sitebuilderLuc Pattyn12-Apr-10 10:55 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 11:14
Jacob Dixon12-Apr-10 11:14 
GeneralRe: Stopping threads (semi-safely).... Pin
Luc Pattyn12-Apr-10 11:23
sitebuilderLuc Pattyn12-Apr-10 11:23 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 11:27
Jacob Dixon12-Apr-10 11:27 
GeneralRe: Stopping threads (semi-safely).... Pin
Luc Pattyn12-Apr-10 11:40
sitebuilderLuc Pattyn12-Apr-10 11:40 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 11:23
Jacob Dixon12-Apr-10 11:23 
GeneralRe: Stopping threads (semi-safely).... Pin
William Winner12-Apr-10 11:01
William Winner12-Apr-10 11:01 
With the original code you showed, I would normally put it into its own class, but if you didn't something like this:

C#
//The event that will be fired upon completion
private delegate void ApplicationsLoadedDel(List<Product> apps);
private event ApplicationsLoadedDel ApplicationsLoaded;

private void frmMain_Load(object sender, EventArgs e)
{
   //Create the new thread
   appThread = new Thread(new ThreadStart(GetApplications));
   appThread.IsBackground = true;

   //add the event handler
   this.ApplicationsLoaded += AddApplications;
   
   //Start the thread
   appThread.Start();
}

private void LoadApplications()
{
     //Just run the WMI_Commands and return the apps
     WMI_Commands wmi = new WMI_Commands(Username, Password,
                            System.Management.ImpersonationLevel.Impersonate, 
                            System.Management.AuthenticationLevel.Default);

     //Get the list of apps
     List<Product> products = wmi.InstalledApplications(NetBios);

     //Raise the event
     ApplicationsLoaded(products);
}

Delegate void AddApplicationsDel(List<Product> products)

private void AddApplications(List<Product> products)
{
   if (this.InvokeRequired)
      this.Invoke(new AddApplciationsDel(Address of AddApplications),
                  new Object() {products});

   foreach (Product p in products)
   {
       AddApplication(p);
   }

   products = null;

   SetPBVisible("pbapplications", false);
}

GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 11:07
Jacob Dixon12-Apr-10 11:07 
GeneralRe: Stopping threads (semi-safely).... Pin
William Winner12-Apr-10 12:49
William Winner12-Apr-10 12:49 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 13:40
Jacob Dixon12-Apr-10 13:40 
AnswerRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 14:38
Jacob Dixon12-Apr-10 14:38 
GeneralRe: Stopping threads (semi-safely).... Pin
DaveyM6912-Apr-10 14:46
professionalDaveyM6912-Apr-10 14:46 
AnswerRe: Stopping threads (semi-safely).... Pin
DaveyM6912-Apr-10 14:44
professionalDaveyM6912-Apr-10 14:44 
QuestionMultithreaded drawing Pin
Groulien12-Apr-10 9:07
Groulien12-Apr-10 9:07 
AnswerRe: Multithreaded drawing Pin
Tarakeshwar Reddy12-Apr-10 9:37
professionalTarakeshwar Reddy12-Apr-10 9:37 
AnswerRe: Multithreaded drawing Pin
ntrceptr12-Apr-10 9:46
ntrceptr12-Apr-10 9:46 
AnswerRe: Multithreaded drawing Pin
William Winner12-Apr-10 10:16
William Winner12-Apr-10 10:16 
QuestionUser and Password Prompt Pin
Jassim Rahma12-Apr-10 5:59
Jassim Rahma12-Apr-10 5:59 
AnswerRe: User and Password Prompt Pin
Dave Kreskowiak12-Apr-10 6:14
mveDave Kreskowiak12-Apr-10 6:14 
GeneralRe: User and Password Prompt Pin
Jassim Rahma12-Apr-10 6:28
Jassim Rahma12-Apr-10 6:28 
GeneralRe: User and Password Prompt Pin
J4amieC12-Apr-10 6:35
J4amieC12-Apr-10 6:35 
AnswerRe: User and Password Prompt Pin
Ravi Bhavnani12-Apr-10 19:17
professionalRavi Bhavnani12-Apr-10 19:17 
QuestionWebBrowser Control - .NET 3.5 - C# Pin
Jon Braunsma12-Apr-10 4:58
Jon Braunsma12-Apr-10 4:58 
AnswerRe: WebBrowser Control - .NET 3.5 - C# Pin
Not Active12-Apr-10 5:26
mentorNot Active12-Apr-10 5:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.