Click to See Complete Forum and Search --> : Memory error after invoking explorer


meshman
September 30th, 2008, 11:58 AM
I have this in my code, under a context menu selection:

Process.Start("explorer.exe", "C:\\");

The program runs fine and I select this item from the context menu. The explorer window opens no problem and then the program stops in program.cs on this line:

Application.Run(new Form1());

"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

The really strange thing is, if I step through this in debug, I can open the window over and over no problem. The second I remove the breapoint and run it, it crashes like above.

Any ideas? It seems to have a mind of its own.

Thanks!

darwen
September 30th, 2008, 12:10 PM
Are you trying to do an Application.Run from inside an Application.Run ? This won't work. You should already have an Application.Run in the main() function of your application for you to have a context menu in the first place.

Application.Run executes the windows message loop for your application (i.e. it processes all the windows messages for your application), with the form which it's given as the main top level form (i.e. the form which will close the application if it's closed). So you should only have and only need one windows message loop for each application.

What are you trying to do exactly ?

Darwen.

meshman
September 30th, 2008, 08:49 PM
"What are you trying to do exactly ?"

An on screen grid contains a path and filename. A context menu has the function, "Open contaning folder". I'm simply tring to have the application open an explorer window with the folder in the grid as the argument.

I wasn't sure if it was something to do with the grid value I was passing it so I hard coded one, as above. Even a valid hard coded path produces the error, *after* the explorer window is successfully opened.

Is there a different/better method for running a process such as explorer.exe from within a C# program?

Thanks!