Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restart an application

Status
Not open for further replies.

ZmrAbdulla

Technical User
Apr 22, 2003
4,364
AE
My application requires a restart at a certain point.
I was trying like this
Code:
  Private Sub LogOutToolStripMenuItem_Click..........
        If MessageBox.Show("Please confirm log out", 
"Confirm", 
MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK Then

            ....
		......
		.....
		.....
            MessageBox.Show("application requires a restart")
            Restart()
        End If
    End Sub
'==========================
    Public Shared Sub Restart()
        Application.Restart()
    End Sub
I am getting an error
Code:
System.InvalidOperationException was unhandled
  Message="Collection was modified; enumeration operation may not execute."
  Source="mscorlib"
Any help on this..


________________________________________________________
Zameer Abdulla
Help to find Missing people
 
I have seen the error 'Collection was modified' when I am using For Each Loops, this happens when an item in the array is removed whilst the program is cycling through the array.

I don't know if this helps
 
I don't have any loop at that moment.

By the way can you tell me if the code I am using correct or not?

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Apart from the ".........." ;-) evertything works fine for me in a .Net 2.0 environment.

What if you put a try catch an try it a second time in the catch part?

Christiaan Baes
Belgium

"My old site" - Me
 
Thanks chrissie,
tried this..
Code:
    Public Shared Sub Restart()
        Try
            Application.Restart()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

and the message was
Code:
---------------------------

---------------------------
Collection was modified; enumeration operation may not execute.
---------------------------
OK   
---------------------------
and the application was not closed


________________________________________________________
Zameer Abdulla
Help to find Missing people
 
I was thinking this

Try
Application.Restart()
Catch ex As Exception
MessageBox.Show(ex.Message)
messagebox.show("try again")
application restart()
End Try

Christiaan Baes
Belgium

"My old site" - Me
 
Brilliant!!
It works..


________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top