[Mono-dev] An generic error occurred in GDI +
Sebastien Pouliot
sebastien.pouliot at gmail.com
Mon May 12 09:55:28 EDT 2008
Hey,
On Fri, 2008-05-09 at 09:33 +0530, Umesh Chape wrote:
> Hi ,
> I am using MonoTorrent.dll 0.0.0.0 . on Operating system is
> Windows Xp with sp2.
It's difficult to help you without more information. E.g. are you using
the Mono runtime or MS runtime ?
> I got error like this " An generic error occurred in GDI +" . I got
> this error in method UpdateNotifyIcon().
A full stack trace, with line numbers, would be helpful.
> This error got after some hours during downloading.
>
> The methos is like this ,
>
>
> public void UpdateNotifyIcon()
> {
>
> try
> {
> if (this.MainBt.WindowState ==
> FormWindowState.Minimized)
> {
> int iconInt =16;
> double dl = clientEngine.TotalDownloadSpeed;
> double ul = clientEngine.TotalUploadSpeed;
> if (dl == 0 && ul == 0)
> {
> // No acivity: show grey mono icon
> this.MainBt.NotifyIconSystray.Icon =
> ResourceHandler.GetIcon("mono_grey", iconInt, iconInt);
> }
> else
> {
> // Build a system tray icon with downloadspeed
> indication
> if (maxDownload == 0)
> {
> maxDownload =
> clientEngine.Settings.GlobalMaxDownloadSpeed;
> // With a minimimum of 16 Kb (1 Kb per
> pixel)
> maxDownload = 1024 * 16;
> }
> if (maxDownload < dl)
> // If no MaxDownloadSpeed is given, create
> your own temporarily
> maxDownload = (int)(dl * 1.25);
>
> // Calculate the dimensions and position of
> the progress indicator
> int h = (int)(dl / (maxDownload / iconInt));
> int w = 3;
> int x = iconInt - w;
> int y = iconInt - h;
>
>
> Bitmap bmp = new Bitmap(iconInt,
> iconInt);
>
> Graphics grs = Graphics.FromImage(bmp);
> grs.DrawIcon(mono, 0, 0);
> grs.FillRectangle(Brushes.Green, x, y, w, h);
> Icon sysIcon =
> Icon.FromHandle(bmp.GetHicon());
At this point 'bmp' is out of scope and the GC is free to collect it
whenever it wishes. I don't recall if the handle returned by GetHicon is
still valid after the bitmap (or it's graphics) has been collected. If
it's not (valid) then this is likely your problem.
> this.MainBt.NotifyIconSystray.Icon = sysIcon;
> }
>
> // Show info text when hovering over system tray
> icon
> string niTxt = Application.ProductName + " " +
> Application.ProductVersion
> + "\nDown: " +
> FormatSpeedValue(dl).ToString()
> + " | Up: " +
> FormatSpeedValue(ul).ToString();
>
> this.MainBt.NotifyIconSystray.Text = niTxt;
> }
> }
> catch (Exception)
> {
>
> throw;
> }
>
>
>
> }
>
> --
> Regards,
> Umesh S.Chape
> +91 9422228738
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
More information about the Mono-devel-list
mailing list