looping ArgumentException ?

L

Lloyd Dupont

I have a multiform application.
my top level run code looks like that.

Form appForm1, appForm2, appForm3, ...
.....
while(true)
try
{
Application.Run(appForm1);
return;
}
catch(Exception ex)
{
Hide(currentForm)
Show(appForm1);
MessageBox(ex.Message);
}

so, as you see, in case of exception, I display the 1st, welcome form (hide
the other) and display an error message.

now what happened, I have a MenuItem which call a method (which should
display an other form) which throw an exception.

and then I get caught in an infinite loop where Application.Run()
continuously throw ArgumentException and there is no user code involved, nor
exception message or inner exception ...

any tips ?
 
L

Lloyd Dupont

more info, I get the complete stack trace:
System.Windows.Forms.dll!AGL.MISC.HandleAr(AGL.PAL_ERROR ar = BadParam) +
0x44 bytes

System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows
..Forms.Form fm = {System.Windows.Forms.Form}) + 0x21 bytes
ihookDB.exe!ihookDB.ihookDB.Run() Line 56 C#
ihookDB.exe!ihookDB.ihookDB.Main(string[] args = {Length=0}) Line 47 C#

any ideas ?
 
J

Jonathan Wells [msft]

Hi Lloyd,

Here is what a developer on the .NET Compact Framework team had to say about
your issue:
Looking at our code, it's not safe to call Application.Run more then once
for a given thread. The ArgumentException is probably occurring because a
different Form instance is being used for the parameter to Application.Run
(you can only have 1 main form per thread), but I would recommend the
customer be aware that there is a known issue with multiple calls to
Application.Run and they should be sure to test their code under SP1.


HTH to clarify this issue.

-j
--
Jonathan Wells
Product Manager
..NET Compact Framework
Check out the .NET Compact Framework FAQ at:
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.

Lloyd Dupont said:
more info, I get the complete stack trace:
System.Windows.Forms.dll!AGL.MISC.HandleAr(AGL.PAL_ERROR ar = BadParam) +
0x44 bytes

System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows
.Forms.Form fm = {System.Windows.Forms.Form}) + 0x21 bytes
ihookDB.exe!ihookDB.ihookDB.Run() Line 56 C#
ihookDB.exe!ihookDB.ihookDB.Main(string[] args = {Length=0}) Line 47 C#

any ideas ?

Lloyd Dupont said:
I have a multiform application.
my top level run code looks like that.

Form appForm1, appForm2, appForm3, ...
....
while(true)
try
{
Application.Run(appForm1);
return;
}
catch(Exception ex)
{
Hide(currentForm)
Show(appForm1);
MessageBox(ex.Message);
}

so, as you see, in case of exception, I display the 1st, welcome form (hide
the other) and display an error message.

now what happened, I have a MenuItem which call a method (which should
display an other form) which throw an exception.

and then I get caught in an infinite loop where Application.Run()
continuously throw ArgumentException and there is no user code involved, nor
exception message or inner exception ...

any tips ?
 
L

Lloyd Dupont

thanks Jonathan.
I think I do understand my issue.
but how could I have an application resistant to exception ?

my idea was not to catch all potential exception (which might appear
anywhere in the code, isn't it ?) (but I already catch the obvious potential
one, like database access and such) and catch them at the top level, display
a nice popup, and restart on the welcome window (thus preventing the
exception to occur in a loop like in a paint)

what would you recommand me to catch exception and continue ?

Jonathan Wells said:
Hi Lloyd,

Here is what a developer on the .NET Compact Framework team had to say about
your issue:
Looking at our code, it's not safe to call Application.Run more then once
for a given thread. The ArgumentException is probably occurring because a
different Form instance is being used for the parameter to Application.Run
(you can only have 1 main form per thread), but I would recommend the
customer be aware that there is a known issue with multiple calls to
Application.Run and they should be sure to test their code under SP1.


HTH to clarify this issue.

-j
--
Jonathan Wells
Product Manager
.NET Compact Framework
Check out the .NET Compact Framework FAQ at:
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.

Lloyd Dupont said:
more info, I get the complete stack trace:
System.Windows.Forms.dll!AGL.MISC.HandleAr(AGL.PAL_ERROR ar =
BadParam)
+
0x44 bytes
System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows
.Forms.Form fm = {System.Windows.Forms.Form}) + 0x21 bytes
ihookDB.exe!ihookDB.ihookDB.Run() Line 56 C#
ihookDB.exe!ihookDB.ihookDB.Main(string[] args = {Length=0}) Line 47 C#

any ideas ?

Lloyd Dupont said:
I have a multiform application.
my top level run code looks like that.

Form appForm1, appForm2, appForm3, ...
....
while(true)
try
{
Application.Run(appForm1);
return;
}
catch(Exception ex)
{
Hide(currentForm)
Show(appForm1);
MessageBox(ex.Message);
}

so, as you see, in case of exception, I display the 1st, welcome form (hide
the other) and display an error message.

now what happened, I have a MenuItem which call a method (which should
display an other form) which throw an exception.

and then I get caught in an infinite loop where Application.Run()
continuously throw ArgumentException and there is no user code
involved,
nor
exception message or inner exception ...

any tips ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top