Delphin Posted January 29, 2008 Report Share Posted January 29, 2008 When I do : Chart mChart = new Chart(); I get the following exception : Insufficient memory to continue the execution of the program. The computer has 3 Go of Ram, the program using ChartFx 2005 only uses 50Mo when crash occurres. Any idea ? Thanks. Quote Link to comment Share on other sites More sharing options...
Frank Posted February 2, 2008 Report Share Posted February 2, 2008 Please attach a sample project that reproduces the problem. Quote Link to comment Share on other sites More sharing options...
Delphin Posted February 6, 2008 Author Report Share Posted February 6, 2008 private void CreateChartFiles(string pLogin, string pCanonicalName, CReachabilityInfo pReachabilityInfo, CUptimeInfo[] pUptimeInfoList, string pWorkingDirectory){ if (pUptimeInfoList.Length == 0) { return; } bool bIsReachable = !pReachabilityInfo.IsUnreachable; // FAILS HERE ON = new Chart(); Chart chart = new Chart(); DataTable dtData = new DataTable(); dtData.Columns.Add(new DataColumn("Old uptimes", typeof(double))); DataRow dtRow = null; double maxY = 0; double bestOldUptime = 0; double currentUptime = -1; if (bIsReachable) { currentUptime = pUptimeInfoList[0].NumberOfDays; } for (int i = pUptimeInfoList.Length - 1; i > 0; i--) { dtRow = dtData.NewRow(); double dayUptime = pUptimeInfoList.NumberOfDays; dtRow["Old uptimes"] = dayUptime; dtData.Rows.Add(dtRow); if (dayUptime > bestOldUptime) { bestOldUptime = dayUptime; maxY = dayUptime; } } if (bIsReachable) { dtRow = dtData.NewRow(); if (currentUptime < bestOldUptime) { dtRow["Old uptimes"] = bestOldUptime; dtData.Rows.Add(dtRow); dtRow = dtData.NewRow(); } dtRow["Old uptimes"] = currentUptime; dtData.Rows.Add(dtRow); if (pUptimeInfoList[0].NumberOfDays > maxY) { maxY = pUptimeInfoList[0].NumberOfDays; } } chart.DataSource = dtData; chart.Data.Series = 1; if (bIsReachable) { if (currentUptime < bestOldUptime) { CustomLegendItem customLegendItem_1 = new CustomLegendItem(); CustomLegendItem customLegendItem_2 = new CustomLegendItem(); customLegendItem_1.Color = Color.Red; customLegendItem_1.MarkerShape = MarkerShape.Rect; customLegendItem_1.Text = "Best uptime"; customLegendItem_2.Color = Color.Green; customLegendItem_2.MarkerShape = MarkerShape.Rect; customLegendItem_2.Text = "Current uptime"; chart.LegendBox.CustomItems.Add(customLegendItem_1); chart.LegendBox.CustomItems.Add(customLegendItem_2); chart.Points[chart.Data.Points - 2].Color = Color.Red; chart.Points[chart.Data.Points - 1].Color = Color.Green; } else { CustomLegendItem customLegendItem = new CustomLegendItem(); customLegendItem.Color = Color.Green; customLegendItem.MarkerShape = MarkerShape.Rect; customLegendItem.Text = "Current uptime"; chart.LegendBox.CustomItems.Add(customLegendItem); chart.Points[chart.Data.Points - 1].Color = Color.Green; } } chart.AxisY.Max = maxY + 10; chart.AxisX.Visible = false; chart.Gallery = Gallery.Bar; chart.AxisY.Title.Text = "Days"; chart.LegendBox.Dock = DockArea.Bottom; chart.LegendBox.Border = DockBorder.None; CUptimeImageInfo uptimeImageInfo = m_Settings.UserOutputsInfo.UptimeImageInfo; chart.Height = uptimeImageInfo.Height; chart.Width = uptimeImageInfo.Width; string sTitle = pCanonicalName; if (!bIsReachable) { sTitle += " [unreachable]"; } TitleDockable title = new TitleDockable(sTitle); title.Font = new Font(FontFamily.GenericMonospace, 10, FontStyle.Bold); chart.Titles.Add(title); string sSubTitle = string.Format("{0}, {1}", CUtilities.GetStrCurrentDate(), CUtilities.GetStrCurrentTime()); TitleDockable subTitle = new TitleDockable(sSubTitle); subTitle.Font = new Font(FontFamily.GenericMonospace, 9); subTitle.TextColor = Color.Gray; chart.Titles.Add(subTitle); chart.Border = new SimpleBorder(SimpleBorderType.Color, Color.Black); chart.Background = new SolidBackground(Color.White); string chartFilePath = Path.Combine(pWorkingDirectory, uptimeImageInfo.FileName); CChartFxTools.Save(chart, chartFilePath, eImageFormat.Png);} CChartFxTools.Save() declaration: using System.IO;using System.Drawing;using System.Drawing.Imaging;using Net.ServPlex.Service.Constants;using ChartFX.WinForms;namespace Net.ServPlex.Service.ChartFxTools{ public static class CChartFxTools { public static void Save(Chart pChart, string pImagePath, eImageFormat pImageFormat) { string bmpFilePath = Path.ChangeExtension(pImagePath, ".bmp"); pChart.Export(FileFormat.Bitmap, bmpFilePath); Convert(bmpFilePath, pImageFormat); } private static void Convert(string pBmpFile, eImageFormat pImageFormat) { if (pBmpFile == null) { throw new ArgumentNullException("The BmpFile parameter cannot be null"); } if (!File.Exists(pBmpFile)) { throw new FileNotFoundException("Cannot find the " + pBmpFile + " file"); } Bitmap bitmap = null; ImageFormat imageFormat = GetImageFormat(pImageFormat); string newFilePath = Path.ChangeExtension(pBmpFile, pImageFormat.ToString().ToLower()); if (File.Exists(newFilePath)) { try { File.Delete(newFilePath); } catch(System.Exception x) { } } try { bitmap = new Bitmap(pBmpFile); bitmap.Save(newFilePath, imageFormat); } catch (System.Exception x) { throw; } finally { #region [ Cleaning memory ] if (bitmap != null) { bitmap.Dispose(); bitmap = null; } try { File.Delete(pBmpFile); } catch (System.Exception x) { } #endregion } } private static ImageFormat GetImageFormat(eImageFormat pImageFormat) { switch (pImageFormat) { case eImageFormat.Jpeg: return ImageFormat.Jpeg; case eImageFormat.Gif: return ImageFormat.Gif; case eImageFormat.Png: return ImageFormat.Png; } return ImageFormat.Png; } }} CreateChartFiles() method is called in a while(true) with no break + Sleep(). Error occures after ~2 days. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.