Reputation: 3
at the moment I do learn C# in an 8 week course. I have one small programm that will get me only an OutOfMemoryException.
But I really do not know why this Exception is called. I mean that the Windows Task Manager shows that I use only 4 of 16 GB RAM. Even if I try to test this programm after I restart the computer.
I have one form that should to the work ... but I do not see the mistake.
Following you will see the code of the only Button in this application.
private void cmdAuswahl_Click(object sender, EventArgs e)
{
Graphics z = CreateGraphics();
Font df = new Font("Verdana", 11);
SolidBrush pinsel = new SolidBrush(Color.Black);
OpenFileDialog ofd = new OpenFileDialog();
Image bild;
z.Clear(BackColor);
ofd.InitialDirectory = "C:\\Temp";
ofd.Title = "Bitte eine Bilddatei wählen";
ofd.Filter = "Bild-Dateien (*.jpg; *.gif)|*.jpg; *.gif";
if (ofd.ShowDialog() == DialogResult.OK)
{
bild = Image.FromFile(ofd.FileName);
z.DrawImage(bild, 20, 40);
z.DrawString("Breite: " + bild.Width + ", Höhe: " +
bild.Height, df, pinsel, 20, 20);
}
else
MessageBox.Show("Keine Bilddatei ausgewählt");
}
I start the application with "crtl + f5" and click on the button. After this I select one image.jpg with 122 KB.
after this I get the OutOfMemoryException
Informationen über das Aufrufen von JIT-Debuggen anstelle dieses Dialogfelds finden Sie am Ende dieser Meldung.
************** Ausnahmetext **************
System.OutOfMemoryException: Nicht genügend Arbeitsspeicher.
bei System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
bei System.Drawing.Image.FromFile(String filename)
bei ZeichnenBild.Form1.cmdAuswahl_Click(Object sender, EventArgs e) in D:\CSharp\Kurs\W6T1 - 7-01\Zeichnen\10.4.1_ZeichnenBild\ZeichnenBild\Form1.cs:Zeile 31.
bei System.Windows.Forms.Control.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnClick(EventArgs e)
bei System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
bei System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.ButtonBase.WndProc(Message& m)
bei System.Windows.Forms.Button.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Geladene Assemblys **************
mscorlib
Assembly-Version: 4.0.0.0.
Win32-Version: 4.7.3056.0 built by: NET472REL1.
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll.
----------------------------------------
ZeichnenBild
Assembly-Version: 1.0.0.0.
Win32-Version: 1.0.0.0.
CodeBase: file:///D:/CSharp/Kurs/W6T1%20-%207-01/Zeichnen/10.4.1_ZeichnenBild/ZeichnenBild/bin/Debug/ZeichnenBild.exe.
----------------------------------------
System.Windows.Forms
Assembly-Version: 4.0.0.0.
Win32-Version: 4.7.3056.0 built by: NET472REL1.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll.
----------------------------------------
System
Assembly-Version: 4.0.0.0.
Win32-Version: 4.7.3056.0 built by: NET472REL1.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll.
----------------------------------------
System.Drawing
Assembly-Version: 4.0.0.0.
Win32-Version: 4.7.3056.0 built by: NET472REL1.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll.
----------------------------------------
System.Configuration
Assembly-Version: 4.0.0.0.
Win32-Version: 4.7.3056.0 built by: NET472REL1.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll.
----------------------------------------
System.Core
Assembly-Version: 4.0.0.0.
Win32-Version: 4.7.3056.0 built by: NET472REL1.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll.
----------------------------------------
System.Xml
Assembly-Version: 4.0.0.0.
Win32-Version: 4.7.3056.0 built by: NET472REL1.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll.
----------------------------------------
System.Drawing.resources
Assembly-Version: 4.0.0.0.
Win32-Version: 4.7.3056.0 built by: NET472REL1.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing.resources/v4.0_4.0.0.0_de_b03f5f7f11d50a3a/System.Drawing.resources.dll.
----------------------------------------
System.Windows.Forms.resources
Assembly-Version: 4.0.0.0.
Win32-Version: 4.7.3056.0 built by: NET472REL1.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_de_b77a5c561934e089/System.Windows.Forms.resources.dll.
----------------------------------------
mscorlib.resources
Assembly-Version: 4.0.0.0.
Win32-Version: 4.7.3056.0 built by: NET472REL1.
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_de_b77a5c561934e089/mscorlib.resources.dll.
----------------------------------------
************** JIT-Debuggen **************
Um das JIT-Debuggen (Just-In-Time) zu aktivieren, muss in der
Konfigurationsdatei der Anwendung oder des Computers
(machine.config) der jitDebugging-Wert im Abschnitt system.windows.forms festgelegt werden.
Die Anwendung muss mit aktiviertem Debuggen kompiliert werden.
Zum Beispiel:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
Wenn das JIT-Debuggen aktiviert ist, werden alle nicht behandelten
Ausnahmen an den JIT-Debugger gesendet, der auf dem
Computer registriert ist, und nicht in diesem Dialogfeld behandelt.
Picture of the Task Manager, open Application and the Error
Upvotes: 0
Views: 280
Reputation: 1664
looks like you are compiling as x86, x86 processes can't have more than 2GB of ram. Compile as x64. Also, for a single image this is too much memory, there is something unsual going on
Upvotes: 2