   [.net] C# .NET (v1.1) - Fun with Forms and a ProgressBar Control
  Hi guys,I've been writing my own little version of Task Manager as a nice way to become more familiar with how to work with the common UI controls found in the ToolBox and I've come up with a bit of a snag.I have a method in my startup form, called LoadProcesses(), which is being called from the Form_Load event handler.  This works great, but can take a couple of seconds before anything shows up, so what I wanted to do, was to invoke a dialog box just before the call to LoadProcesses() and update a ProgressBar control on the new dialog, based on the progress of the LoadProcesses() method.Here's LoadProcesses() to illustrate what I mean:/// <summary>/// Method to obtain information about the currently loaded processes./// </summary>private void LoadProcesses(){// Retrieve the list of processes, using this to create// an accurate increment for the progress bar control.Process[] processList = Process.GetProcesses();int increment = 100 / processList.Length;// Loop through all of the processes, adding them to the root node.for (int i = 0; i < processList.Length; i++){TreeNode nodeProcess = new TreeNode();try{nodeProcess.Text = processList.MainModule.ModuleName;}catch (System.ComponentModel.Win32Exception){nodeProcess.Text = processList.ProcessName;}finally{treeProcesses.Nodes.Add(nodeProcess);}// Increment the status of the progress bar.// ...}}As you can see, from a design point of view, it doesn't seem to make much sense to dump code for the ProgressBar into this method as well.  I'd rather separate it, but how could I accomplish this?  Sorry if this sounds like a stupid question but it is bugging me.  I'm asking because surely this is a case of mixing UI and business logic together?Thanks for your time.   
  You could use events to do that.   ;  Well god damn.  So I could!  Nice, I've always needed a practical use for them (being as the examples just keep talking about the Click event and nothing else).Cheers for that!   ;  You'll note that the runtime doesn't allow threads other than the thread creating a control to modify it. To update the progress bar "from" the loading thread, you will ned to use Control.Invoke().This is where you will also find a good use of anonymous methods [wink]   ;  Hey thanks for that, Enselic.  That actually answered another question I had. [smile]   