473,394 Members | 1,761 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,394 software developers and data experts.

Odd "Unhandled Exception" error

I often use the following code to check if a program is already running:

if
(Process.GetProcessesByName(Process.GetCurrentProc ess().ProcessName).Length
1) ...


This works find on all of my systems, but a student using one of my programs
reported that he was getting an "Unhandled Exception" trying to load my
program. This is even stranger since the code in question is in a try/catch
block. I took a look at the student's system but couldn't find any
immediately obvious that would cause this problem. The fact that it's
happening with two different applications indicates that there is some sort
of problem with his system. I suspect the .NET Framework but a reinstall of
that didn't help. Is there some other system process that would cause this
error to occur? I suspect a reinstall of Windows would solve the problem but
there has to be something a bit less drastic. Any suggestions would be
appreciated.
Nov 16 '05 #1
6 2320
Paul Steele wrote:
I often use the following code to check if a program is already running:

if
(Process.GetProcessesByName(Process.GetCurrentProc ess().ProcessName).Length
> 1) ...
This works find on all of my systems, but a student using one of my programs
reported that he was getting an "Unhandled Exception" trying to load my
program.

This is even stranger since the code in question is in a try/catch block.
[How could you be sure on this if you encounter an unhanded exception,
this seems contradictory to me]

I took a look at the student's system but couldn't find any immediately obvious that would cause this problem. The fact that it's
happening with two different applications indicates that there is some sort
of problem with his system. I suspect the .NET Framework but a reinstall of
that didn't help. Is there some other system process that would cause this
error to occur? I suspect a reinstall of Windows would solve the problem but
there has to be something a bit less drastic. Any suggestions would be
appreciated.

Nov 16 '05 #2
Try this one instead:

// This will be set to true if this process can own the mutex.
bool pobjIOwnMutex = false;

// Try and get ownership of a mutex who's name is known.
System.Threading.Mutex pobjMutex = new System.Threading.Mutex(true,
"MyMutex", out
pobjIOwnMutex);

// If the mutex is owned by this process, then run the application.
if (pobjIOwnMutex)
{
// Run the application.
Application.Run(new frmMain());
}
else
{
//exit application
}

This works always.

Regards Alexander
"John Sun" wrote:
Paul Steele wrote:
I often use the following code to check if a program is already running:

if
(Process.GetProcessesByName(Process.GetCurrentProc ess().ProcessName).Length
> 1) ...


This works find on all of my systems, but a student using one of my programs
reported that he was getting an "Unhandled Exception" trying to load my
program.

This is even stranger since the code in question is in a try/catch block.
[How could you be sure on this if you encounter an unhanded exception,
this seems contradictory to me]

I took a look at the student's system but couldn't find any
immediately obvious that would cause this problem. The fact that it's
happening with two different applications indicates that there is some sort
of problem with his system. I suspect the .NET Framework but a reinstall of
that didn't help. Is there some other system process that would cause this
error to occur? I suspect a reinstall of Windows would solve the problem but
there has to be something a bit less drastic. Any suggestions would be
appreciated.

Nov 16 '05 #3

"John Sun" <js***********@gmail.com> wrote in message
news:ui**************@TK2MSFTNGP12.phx.gbl...
Paul Steele wrote:
I often use the following code to check if a program is already running:

if
(Process.GetProcessesByName(Process.GetCurrentProc ess().ProcessName).Length
> 1) ...


This works find on all of my systems, but a student using one of my
programs reported that he was getting an "Unhandled Exception" trying to
load my program.

This is even stranger since the code in question is in a try/catch block.
[How could you be sure on this if you encounter an unhanded exception,
this seems contradictory to me]


I don't disagree, but if I comment out the code I no longer get the error.
In either program. It's very weird...
Nov 16 '05 #4
This may or may not work. Unfortunately just solving this problem won't be
sufficient. I didn't want to go into all the gory details but even if I
comment out the code causing the initial error, I get another strange error
later on in the program. I only had the student's system for 30 minutes so I
didn't get a chance to narrow down the cause of the second error (which
incidentally works fine on other students' systems). I forgot to make note
of the exception error, but it was something about not being able to start a
process (I use quite a few threads in the application). I suspect the second
error is related to the first error. Something very weird is going on...

"Alexander Wehrli" <Al*************@discussions.microsoft.com> wrote in
message news:66**********************************@microsof t.com...
Try this one instead:

// This will be set to true if this process can own the mutex.
bool pobjIOwnMutex = false;

// Try and get ownership of a mutex who's name is known.
System.Threading.Mutex pobjMutex = new System.Threading.Mutex(true,
"MyMutex", out
pobjIOwnMutex);

// If the mutex is owned by this process, then run the application.
if (pobjIOwnMutex)
{
// Run the application.
Application.Run(new frmMain());
}
else
{
//exit application
}

This works always.

Regards Alexander
"John Sun" wrote:
Paul Steele wrote:
> I often use the following code to check if a program is already
> running:
>
> if
> (Process.GetProcessesByName(Process.GetCurrentProc ess().ProcessName).Length
> > 1) ...
>
> This works find on all of my systems, but a student using one of my
> programs
> reported that he was getting an "Unhandled Exception" trying to load my
> program.

This is even stranger since the code in question is in a try/catch
block.
[How could you be sure on this if you encounter an unhanded exception,
this seems contradictory to me]

I took a look at the student's system but couldn't find any
> immediately obvious that would cause this problem. The fact that it's
> happening with two different applications indicates that there is some
> sort
> of problem with his system. I suspect the .NET Framework but a
> reinstall of
> that didn't help. Is there some other system process that would cause
> this
> error to occur? I suspect a reinstall of Windows would solve the
> problem but
> there has to be something a bit less drastic. Any suggestions would be
> appreciated.
>
>

Nov 16 '05 #5
Paul Steele wrote:
"John Sun" <js***********@gmail.com> wrote in message
news:ui**************@TK2MSFTNGP12.phx.gbl...
Paul Steele wrote:
I often use the following code to check if a program is already running:

if
(Process.GetProcessesByName(Process.GetCurrentP rocess().ProcessName).Length
> 1) ...

This works find on all of my systems, but a student using one of my
programs reported that he was getting an "Unhandled Exception" trying to
load my program.

This is even stranger since the code in question is in a try/catch block.
[How could you be sure on this if you encounter an unhanded exception,
this seems contradictory to me]

I don't disagree, but if I comment out the code I no longer get the error.
In either program. It's very weird...

Hi, Paul

Won't it be more helpful if you could post more complete code, how did
you implement the try .. catch ..., which line of code you comment out
before and after you got an exception.
Nov 16 '05 #6
"Jianwei Sun" <js***********@gmail.com> wrote in message
news:uN**************@tk2msftngp13.phx.gbl...
I don't disagree, but if I comment out the code I no longer get the
error. In either program. It's very weird...
Hi, Paul

Won't it be more helpful if you could post more complete code, how did you
implement the try .. catch ..., which line of code you comment out before
and after you got an exception.


Not sure that it will help, but here it is:

static void Main()
{
try
{
if
(Process.GetProcessesByName(Process.GetCurrentProc ess().ProcessName).Length 1)

{
MessageBox.Show("The program is already running!");
}
else
{
Application.Run(new ExamProctorForm());
}
}
catch
{
MessageBox.Show("An error has occured!");
}
}

I change the if statement to "if (false)" and I don't get the exception...
Nov 16 '05 #7

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

Similar topics

4
by: Andy | last post by:
Hi, I'm doing a nested pass by reference of a vector. I'm in Vis Studio 2003. Example: vector <unsigned long long> vect; func1(vect); where func1 calls func2(vect);
1
by: Erialc Berts | last post by:
I know why we get this error, but does anyone know how to catch it so that we can display a more helpful message to our users? I am interested both in a .exe and a web site. Thanks in advance...
5
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is ...
0
by: mammucion | last post by:
Trying to automate processing 80,000 data sets through 15 web pages. Application URL creates a new IE instance in which runs first a login form and then runs the rest of the pages in the new...
2
by: whiskers | last post by:
I'm debugging some code and I have to admit that I don't know yet how it works. But I ran into a problem I can't explain The program is a DLL that retrieves raw data from a camera, builds...
0
by: rmcpherson | last post by:
Can someone please help with this problem? I'm trying to go to the last record, make a new record, and save it the database. It just gives me "OleDbException was unhandled" error at da.Update(ds,...
0
by: Gary | last post by:
Trying to install VB6 (learning edition) on Windows XP. When running the SETUP.EXE to install Visual Basic 6.0 it gives the error... "An unhandled win32 exception occured in vs60wiz.exe" or...
8
joedeene
by: joedeene | last post by:
Hello there, I am having a problem and it is frustrating me because I've been trying to figure it out, and I've even modified the code a few times but the same exception occurs: "...
4
by: siddhanta | last post by:
float x = new float; float y = new float; int c=0; using (StreamReader sr = new StreamReader("e: \\CuPeak.dat")) { while (!sr.EndOfStream) {
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.