473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Weird crash after "dragging" NotifyIcon - NullReferenceException

Me
I'm getting a NullReferenceException in Unknown Module when I follow
the below steps to create a simple NotifyIcon app that creates the
context menu on the fly(see a little analysis after the steps).

1. Create a new Windows Forms C# solution (I called mine DBChanger).
2. Replace Form1.cs code with this:

--------------------
using System;

namespace DBChanger
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DBChangerIcon d = new DBChangerIcon();
d.Start();
System.Windows.Forms.Application.Run();
}
}
}
--------------------

3. Create a new class named "DBChangerIcon" and replace code with
this:

--------------------
using System;
using System.Drawing;
using System.Windows.Forms;

namespace DBChanger
{
public class DBChangerIcon
{
NotifyIcon ni;

public void Start()
{
ni = new NotifyIcon();
ni.Icon = new Icon(@"..\..\App.ico");
ni.MouseDown += new MouseEventHandler(ni_MouseDown);

ni.Visible = true;
}

private void miExit_Click(object Sender, EventArgs e)
{
ni.Visible = false;
Application.Exit();
}

private void ni_MouseDown(object Sender, MouseEventArgs e)
{
ContextMenu cm = new ContextMenu();
cm.MenuItems.Add(new MenuItem("E&xit", new
EventHandler(miExit_Click)));

ni.ContextMenu = cm;
}
}
}
--------------------

4. Build and run it.
5. Right click on the tray icon, drag the mouse off the tray icon,
then release the right click.
6. Right click on the tray icon again, release, and click Exit.

That's how I get a NullReferenceException. If I just do step 6
without step 5 then everything works fine.

It happens in the garbage collection during the Application.Exit()
call. Stack trace is:

System.GC.GetTotalMemory
System.Windows.Forms.Application.CollectAllGarbage
System.Windows.Forms.Application.Exit

And it always fails around the second time that function calls
GC.nativeGetTotalMemory();

This is with Framwork 1.1 and I made it in VS.Net 2003.

I can't figure out what I'm missing. Thanks for any help!
Nov 15 '05 #1
3 2086
Me
d0*******@sneakemail.com (Me) wrote in message news:<17**************************@posting.google. com>...
I'm getting a NullReferenceException in Unknown Module when I follow
the below steps to create a simple NotifyIcon app that creates the
context menu on the fly(see a little analysis after the steps).

1. Create a new Windows Forms C# solution (I called mine DBChanger).
2. Replace Form1.cs code with this:

--------------------
using System;

namespace DBChanger
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
DBChangerIcon d = new DBChangerIcon();
d.Start();
System.Windows.Forms.Application.Run();
}
}
}
--------------------

3. Create a new class named "DBChangerIcon" and replace code with
this:

--------------------
using System;
using System.Drawing;
using System.Windows.Forms;

namespace DBChanger
{
public class DBChangerIcon
{
NotifyIcon ni;

public void Start()
{
ni = new NotifyIcon();
ni.Icon = new Icon(@"..\..\App.ico");
ni.MouseDown += new MouseEventHandler(ni_MouseDown);

ni.Visible = true;
}

private void miExit_Click(object Sender, EventArgs e)
{
ni.Visible = false;
Application.Exit();
}

private void ni_MouseDown(object Sender, MouseEventArgs e)
{
ContextMenu cm = new ContextMenu();
cm.MenuItems.Add(new MenuItem("E&xit", new
EventHandler(miExit_Click)));

ni.ContextMenu = cm;
}
}
}
--------------------

4. Build and run it.
5. Right click on the tray icon, drag the mouse off the tray icon,
then release the right click.
6. Right click on the tray icon again, release, and click Exit.

That's how I get a NullReferenceException. If I just do step 6
without step 5 then everything works fine.

It happens in the garbage collection during the Application.Exit()
call. Stack trace is:

System.GC.GetTotalMemory
System.Windows.Forms.Application.CollectAllGarbage
System.Windows.Forms.Application.Exit

And it always fails around the second time that function calls
GC.nativeGetTotalMemory();

This is with Framwork 1.1 and I made it in VS.Net 2003.

I can't figure out what I'm missing. Thanks for any help!


Hmm... Anybody have a better way to create a context menu for a
NotifyIcon on the fly?

Anybody confirm that this happens or doesn't happen on their machine?
I'm using Win2000 Pro with SP3.

Thanks!
Nov 15 '05 #2

"Me" <d0*******@sneakemail.com> wrote in message
news:17**************************@posting.google.c om...
d0*******@sneakemail.com (Me) wrote in message

news:<17**************************@posting.google. com>...
4. Build and run it.
5. Right click on the tray icon, drag the mouse off the tray icon,
then release the right click.
6. Right click on the tray icon again, release, and click Exit.

That's how I get a NullReferenceException. If I just do step 6
without step 5 then everything works fine.

It happens in the garbage collection during the Application.Exit()
call. Stack trace is:

System.GC.GetTotalMemory
System.Windows.Forms.Application.CollectAllGarbage
System.Windows.Forms.Application.Exit

And it always fails around the second time that function calls
GC.nativeGetTotalMemory();

This is with Framwork 1.1 and I made it in VS.Net 2003.

Anybody confirm that this happens or doesn't happen on their machine?
I'm using Win2000 Pro with SP3.

Thanks!

Me (You),

I built this on WinXP SP1a with VS2003Pro, .Net 1.1.

No Problems with the Exception. However the "Exit" context menu stays up
afer the first right click and until you actually close the application.


Nov 15 '05 #3
Me
"TonyM" <Sp*******@Biteme.net> wrote in message news:<_x**********************@news.easynews.com>. ..
"Me" <d0*******@sneakemail.com> wrote in message
news:17**************************@posting.google.c om...
d0*******@sneakemail.com (Me) wrote in message

news:<17**************************@posting.google. com>...
4. Build and run it.
5. Right click on the tray icon, drag the mouse off the tray icon,
then release the right click.
6. Right click on the tray icon again, release, and click Exit.

That's how I get a NullReferenceException. If I just do step 6
without step 5 then everything works fine.

It happens in the garbage collection during the Application.Exit()
call. Stack trace is:

System.GC.GetTotalMemory
System.Windows.Forms.Application.CollectAllGarbage
System.Windows.Forms.Application.Exit

And it always fails around the second time that function calls
GC.nativeGetTotalMemory();

This is with Framwork 1.1 and I made it in VS.Net 2003.

Anybody confirm that this happens or doesn't happen on their machine?
I'm using Win2000 Pro with SP3.

Thanks!

Me (You),

I built this on WinXP SP1a with VS2003Pro, .Net 1.1.

No Problems with the Exception. However the "Exit" context menu stays up
afer the first right click and until you actually close the application.


Thanks for trying it!

I found an XP SP1 machine to test on. That behavior (menus staying
after drag) seems to happen with all tray icons in XP. Weird.

I can reproduce my bug by left clicking instead of right clicking in
step 5. So the last steps that make it fail in XP are:

5. Left click on the tray icon, drag the mouse off the tray icon, then
release the left click.
6. Right click on the tray icon, release, and click Exit.

It's looking like I'd better just not use a tray icon. ;) Shame
really.
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Miles Davenport | last post by:
I would like some advice on what Java server-side alternatives their are to an applet which is a shopping cart application which allows the user to drag-and-drop individual items into "an order"...
5
by: Roger Shrubber | last post by:
I have a page with images that the user can drag from one frame to another. I need them to see a "ghost image" of the image they are dragging, while the original stays put. I use the onmousemove...
10
by: Flare | last post by:
Hi I just read and experimented with normal .net GUI apps and deployed them with notouch deployment strategie as smartclients. Is it just me, or i this an very neglected topic? For me it...
1
by: Seraph | last post by:
I've never posted here before, but I have lurked for quite some time, and have been frustrated to my whits end on what to do about this. Since there is limited support in previous posts (and many...
0
by: blackmagicinc | last post by:
hi, "Show Window Content while Dragging" is the big flaw in windows XP How to programmatically disable "Show Window Content while Dragging" from VB6 ? Thanks in advance...
1
by: | last post by:
Greetings all, I'm at a loss for fixing this problem, so I'm hoping someone out there has seen this and has a solution. Basically, I'm working on an app written in VB.NET 2005 which uses a...
5
by: Tom_F | last post by:
To comp.databases.ms-access -- I am trying to re-number the "tab index" for a large number of controls on a form. When I try to do this one control at a time, Access automatically re-numbers...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.