Application.Run Problem

R

rajendra.mishra

Hi...
I have a windows vb.net application. The StatupObject is a Module
'modMain'.
In the main sub routine i have the following
g_frmMain = New formVMMain
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
Application.Run(New ApplicationContext(g_frmMain))


There is a progress bar in the form which starts everytime a file in a
particular folder is updated.so whenever the file is updated the
progress bar is initialised and shown in the main Form. The application
works fine sometimes but at other times it gives an ArgumentoutofRange
Exception at ' Application.Run(New ApplicationContext(g_frmMain))' this
line. 'Index was out of Range. Must be non negative and less than the
size of the collection.'

Any Help will be appreciated.

Raj
 
C

Chris

Hi...
I have a windows vb.net application. The StatupObject is a Module
'modMain'.
In the main sub routine i have the following
g_frmMain = New formVMMain
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
Application.Run(New ApplicationContext(g_frmMain))


There is a progress bar in the form which starts everytime a file in a
particular folder is updated.so whenever the file is updated the
progress bar is initialised and shown in the main Form. The application
works fine sometimes but at other times it gives an ArgumentoutofRange
Exception at ' Application.Run(New ApplicationContext(g_frmMain))' this
line. 'Index was out of Range. Must be non negative and less than the
size of the collection.'

Any Help will be appreciated.

Raj

Your problem is not on the application.run object, it's in your form
formVMMain. Tell the compiler to break on all exceptions (Debug ->
Exceptions) and then hopefully it will break where the actual exception
is happening.

Chris
 
G

Guest

had the same prob you describe... but it was on
Private Sub me_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

some times it just crashed after displaying correctly...meaning the form was
perfectly displayed/working but, when I did call another window and back then
it crashed.
might help some one if not you.
 
R

rajendra.mishra

Hi Chris/raulavi...

Thanks for the prompt replies

I am not able to catch the exception except at the Application.Run. The
BreakPoints at FormvmMain and elsewhere do not come up...it goes to
this line and throws it...If i handle the exception at Application.run
it goes to catch...but then the application exits itself.

Raj
 
A

Armin Zingler

Hi...
I have a windows vb.net application. The StatupObject is a Module
'modMain'.
In the main sub routine i have the following
g_frmMain = New formVMMain
System.Windows.Forms.Cursor.Current =
System.Windows.Forms.Cursors.Default
Application.Run(New ApplicationContext(g_frmMain))


There is a progress bar in the form which starts everytime a file in
a particular folder is updated.so whenever the file is updated the
progress bar is initialised and shown in the main Form. The
application works fine sometimes but at other times it gives an
ArgumentoutofRange Exception at ' Application.Run(New
ApplicationContext(g_frmMain))' this line. 'Index was out of Range.
Must be non negative and less than the size of the collection.'

Any Help will be appreciated.


What does the callstack window show when the exception occurs? Please
Include the "non-user code" (or "external code") in the window's context
menu.


Armin
 
R

rajendra.mishra

on doing a quick watch it shows the following error

Application.Run(g_frmMain) Run-time exception thrown :
System.InvalidOperationException - It is invalid to start a second
message loop on a single thread. Use Application.RunDialog or
Form.ShowDialog instead.

while the popup message shows the following
"
Index was out of range. Must be non-negative and less than the size of
the collection.
Paramater name: index
"
I have tried using Form.showdialog it gives me the same...for 10 times
it will work fine but sometime it wont...

Raj
 
G

Guest

Why don't you start your program (Vb.Net 2003) from your main sub like;
g_frmMain.Show
Applicaton.Run

Why are you using the new application context? Is this a VB.Net 2005 thing
(I use only 2003 due the problems with 2005 that I've read in this newsgroup).
 

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