|
|
"public void DisplayMessage(Object myReactor, MeltdownEventArgs myMEA)
{
//FormReactor FR = new FormReactor();
String message = myMEA.Message;
delegateReactorMessage(FR.listBoxReactor, message);
}"
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 ?
Christian Graus
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.
Michael
|
|
|
|
|
What do you see in the debugger ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
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.
Thanks,
Michael
namespace ReactorDelegates
{
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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormStartReactor());
//new FormReactor(),
}
}
namespace ReactorDelegates
{
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 FormStartReactor()
{
InitializeComponent();
}
public void buttonStart_Click(object sender, EventArgs e)
{
FormReactor FR = new FormReactor();
Reactor myReactor = new Reactor();
ReactorMonitor myReactorMonitor = new ReactorMonitor(myReactor);
reactorToolStripMenuItem_Click(sender, e);
delegatebuttonBegin(sender, e);
// 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;
}
private void reactorToolStripMenuItem_Click(object sender, EventArgs e)
{
FormReactor mdiChildForm = new FormReactor();
mdiChildForm.MdiParent = this;
mdiChildForm.Show();
}
}
}
namespace ReactorDelegates
{
public partial class FormReactor : Form
{
public FormReactor()
{
InitializeComponent();
this.listBoxReactor.Items.Clear();
this.listBoxReactor.Items.AddRange(new object[] {"Reactor down"});
}
public void ReactorMessage(String message)
{
listBoxReactor.BeginUpdate();
listBoxReactor.Items.Add(message);
listBoxReactor.EndUpdate();
}
public void buttonBegin_Click(object sender, EventArgs e)
{
ReactorMessage("Start Reactor");
}
}
}
namespace ReactorDelegates
{
class ReactorMonitor
{
static FormReactor FR = new FormReactor();
Action<String> delegateReactorMessage = FR.ReactorMessage;
public ReactorMonitor(Reactor myReactor)
{
myReactor.OnMeltdown += new Reactor.MeltdownHandler(DisplayMessage);
}
public void DisplayMessage(Object myReactor, MeltdownEventArgs myMEA)
{
String message = myMEA.Message;
delegateReactorMessage(message);
}
}
}
namespace ReactorDelegates
{
class Reactor
{
Int32 temperature;
String strReactorMessage;
public delegate void MeltdownHandler(Object reactor, MeltdownEventArgs myMEA);
public event MeltdownHandler OnMeltdown;
public Int32 Temperature
{
set
{
temperature = value;
if (temperature > 1000)
{
if (temperature < 2000)
{
strReactorMessage = "Reactor meltdown in progress";
}
else
{
strReactorMessage = "The reactor is critical, YOU ARE DEAD, DEAD, DEAD";
}
MeltdownEventArgs myMEA = new MeltdownEventArgs(strReactorMessage);
OnMeltdown(this, myMEA);
}
}
}
}
}
namespace ReactorDelegates
{
class MeltdownEventArgs : EventArgs
{
String message;
public MeltdownEventArgs(String message)
{
this.message = message;
}
public String Message
{
get
{
return message;
}
}
}
}
|
|
|
|
|
I am using Syste.Collections.Generic.List
I made just a test and noticed that it can ran out of memory with large entrys. Is there a whay to handle "unlimited numbers" of its content.
Is there a diffrent whay to handle arrays with faster accsess without predefineing its array size?
does "delete" command free memory without waiting to get destroyed by Garbage Collectors?
|
|
|
|
|
Saksida Bojan wrote: noticed that it can ran out of memory with large entrys
No, your program ran out of memory. The list will work so long as you have memory for your app.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
Is there a whay of increasing App Memory or shoud i resort to I/O Accsess?
|
|
|
|
|
I guess you need to rethink your design. You may want to keep only a portion of the list in memory at a time and swap unneeded parts back to the hard drive, sort of like a memory mapped file.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I Am doing Memory Scanner, Like Cheat Engine. If I acsess Memory and hdd with method Asynth or Synth what woud be better? Does delete command free Memory without closing process?
|
|
|
|
|
What delete command? Where do you read the data from and what do you need to store in your large list?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The question is, if you buy more RAM, how much will your users need ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
My Process was about 500MB in memory. I Have 2GB of ram. And not all of pshical ram used, let alone windows Virtual Memory
|
|
|
|
|
Well, that is odd. I've had an app in development use 1 gig before. And once you run out of physical memory, it should swap to the HDD.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
public struct ProcessInfo<br />
{<br />
public bool bTaskBar;<br />
public int iProcessID;<br />
public String sTaskBarText;<br />
public String sFileName;<br />
public int iThreads;<br />
<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
List<ProcessInfo> lpi = new List<ProcessInfo>();<br />
<br />
do <br />
{<br />
ProcessInfo pi = new ProcessInfo();<br />
lpi.Add(pi);<br />
} while (true);<br />
}
|
|
|
|
|
First, learn how to post code snippets here.
Second, this code:
static void Main(string[] args)
{
List<processinfo> lpi = new List<processinfo>();
do
{
ProcessInfo pi = new ProcessInfo();
lpi.Add(pi);
} while (true);
}</processinfo></processinfo>
Should look more like this:
static void Main(string[] args)
{
List<processinfo> listOfProcesses = new List<processinfo>();
while (true()
{
ProcessInfo processInfo = new ProcessInfo();
if (processInfo != null)
{
listOfProcesses.Add(processInfo);
}
else
{
break;
}
}
}</processinfo></processinfo>
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.
2. Read rule #8
|
|
|
|
|
You can also get that exception if you have Int32.Max (2,147,483,648) number of items in the list and then try to add another one.
|
|
|
|
|
Thanks for the info. So it was List limitation, not memory. I Hope i wont have to utilize hdd for temp storage.
|
|
|
|
|
You need to allow programs to access more than 2GB of memory on an OS level. Please read your OS manual to set that.
|
|
|
|
|
When new can't allocate the memory, it returns null .
"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
|
|
|
|
|
Hey
All I am trying to do is print a file from c# can't seem to get anything to work. Some of the requirements are:
1) need to have the print dialog box appear
2) print proper file
Thanks,
ZachBob
~Any help is good help
|
|
|
|
|
What sort of file, just text ?
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
|
Hi,
have a look at the Process and ProcessStartInfo classes, and use Verb="Print"; that way
your default PDF reader will do the actual printing. AFAIK that is the easiest way.
There is one disadvantage: the PDF reader will remain open (unless you add more code to close it,
which is a bit tricky).
|
|
|
|