foreach(Control c in Controls)
ComboBox cb = c as ComboBox;
if (cb != null)
cb.SelectedIndex = 0;
this loops through ALL the controls on the current form, that's buttons, checkboxs, textboxes etc. There are a lot of controls on a form. So, as you're looping through, if you try and treat an object that is NOT a checkbox like a checkbox, it will error. Soooooo.... you test to see if the conversion to ComboBox worked. You can't easily select JUST ComboBoxes from a form, you have to go through the controls.
First, your delegate doesn't need to conform to the object/eventargs model, it can have any signature.
Second, it looks like you're trying to pass the listbox to the delegate. Why ? That misses the whole point. The point is, your delegate method should fire in the scope of the listbox, and the code to work with the listbox should run locally. If you're going to pass the listbox, the code could be anywhere, so why use delegates ?
No longer a Microsoft MVP, but still happy to answer your questions.
Thanks, but even so when I start the program it still doesn't pass on the message, start button activtes the begin button whic should send a message a that is not happening whether I use a delegate or not, yet the begin button will load a message.
Everything compiles and runs but nothing happens when the delegate runs the buttonBegin, I expected to see "Start Reactor" as I would when I click on the button itself. Here is an updated copy, which is what I originally had before playing with it to try different ideas.
public delegate void DelegateReactorMessage(String message);
public delegate void DelegatebuttonStart_Click(object sender, EventArgs e);
public delegate void DelegatebuttonBegin_Click(object sender, EventArgs e);
static class Program
/// The main entry point for the application.
public static void Main()
public partial class FormStartReactor : Form
static FormReactor FR = new FormReactor();
Action<String> delegateReactorMessage = FR.ReactorMessage;
DelegatebuttonBegin_Click delegatebuttonBegin = new DelegatebuttonBegin_Click(FR.buttonBegin_Click);
public void buttonStart_Click(object sender, EventArgs e)
FormReactor FR = new FormReactor();
Reactor myReactor = new Reactor();
ReactorMonitor myReactorMonitor = new ReactorMonitor(myReactor);
// Set myReactor to 100 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 100 degrees Celcius");
myReactor.Temperature = 100;
// Set myReactor to 500 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 1500 degrees Celcius");
myReactor.Temperature = 1500;
// Set myReactor to 2000 degrees Celcius
delegateReactorMessage("Setting reactor temperature to 3000 degrees Celcius");
myReactor.Temperature = 3000;
public delegate void MeltdownHandler(Object reactor, MeltdownEventArgs myMEA);
public event MeltdownHandler OnMeltdown;
public Int32 Temperature
temperature = value;
if (temperature > 1000)
if (temperature < 2000)
strReactorMessage = "Reactor meltdown in progress";
strReactorMessage = "The reactor is critical, YOU ARE DEAD, DEAD, DEAD";
public struct ProcessInfo<br />
// Specify if this belongs to TaskBar (Visible)<br />
public bool bTaskBar;<br />
// ProcessID<br />
public int iProcessID;<br />
// Text of TaskBarIfAvaible<br />
public String sTaskBarText;<br />
// FileName<br />
public String sFileName;<br />
// Number of threads<br />
public int iThreads;<br />
static void Main(string args)<br />
List<ProcessInfo> lpi = new List<ProcessInfo>();<br />
do <br />
ProcessInfo pi = new ProcessInfo();<br />
} while (true);<br />
static void Main(string args)
List<processinfo> lpi = new List<processinfo>();
ProcessInfo pi = new ProcessInfo();
} while (true);
Should look more like this:
static void Main(string args)
List<processinfo> listOfProcesses = new List<processinfo>();
ProcessInfo processInfo = new ProcessInfo();
if (processInfo != null)
1) You had an endless loop.
2) Your variable names suck.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
1. I know i had endless loop. I wanted to fill my memory and using Virtual Memory as a test. But didnt happend. It threw me System.OutOfMemoryException. And even your sample has infinitive loop. processInfo will never be null, because you intalize it.