1 Attachment(s)
[RESOLVED] Problem that has me going crazy.
Hey VBFROUM!
I have been working on a program and i am developing the second installment of the beta series. I have a configuration wizard that asks the user some questions then saves the settings when you click finish and restarts the program. When the program restarts, i end up with two instances of my application. i used application.restart()
EDIT:
Check out the techjive website. We are releasing 2.0 in a little (like next week maybe by saturday?) Its okay but its only my first beta
office.techjive.org
Re: Problem that has me going crazy.
Perhaps it would be a good idea if you include which version of vb.net you are using. I tried opening the project in VS2008 and it didn't open.
Re: Problem that has me going crazy.
Quote:
Originally Posted by
Nightwalker83
Perhaps it would be a good idea if you include which version of vb.net you are using. I tried opening the project in VS2008 and it didn't open.
I'm sorry. I ended fixing my problem i was going to origonally post so i rewrote my psot and i forgot to leave that part :) - Anyways i use 2010 and you can open it in 2008 by opening OfficeMonkey 2.1 (BETA).sln in notepad and changing
Microsoft Visual Studio Solution File, Format Version 11.00
to
Microsoft Visual Studio Solution File, Format Version 10.00
I think i got he number write. I'm sorry i forgot to mention this
Re: Problem that has me going crazy.
Did i post this in the wrong forum? I think i may have but not to sure? I have never been clear on what Visual Basic is classified as. Can anyone clarify that for me too?
Re: Problem that has me going crazy.
There are two main types of VB com and .net! VB6 is com and VB 2002 to now are .net. They use a different way of doing things.
Edit:
I found this code here which, checks for the previous instance of a loaded application.
VB Code:
Imports System.Threading
'Form level declaration
Public Class Form1
Dim objMutex As Mutex
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
objMutex = New Mutex(False, "SINGLE_INSTANCE_APP_MUTEX")
If objMutex.WaitOne(0, False) = False Then
objMutex.Close()
objMutex = Nothing
MessageBox.Show("Instance already running")
End
End If
'if you get to this point it's frist instance
'continue with app
End Sub
End Class
Re: Problem that has me going crazy.
Thank you for that. And thank you for that bit of code. I may end up having to do that but I am wondering why its even launching two instances when i want it to restart
Re: Problem that has me going crazy.
I'm not sure I have never used the restart method before.
Re: Problem that has me going crazy.
Okay, I created a quick test porgram with a button that called app to restart. Works like it should closes and reloads. So i am now wondering if its the timer i have in splash scrren? Going to experiment.
Re: Problem that has me going crazy.
Now i got this:
I skipped the config screen and disable timer and go right to main, then close the splash. i added a button to main and added application.restart to its click event. When i click it here it restarts and i end up with one instance? This is weird. it may be my configuration wizard but i havn't figured out how or whats my prbolem. Going to try the button on welcome screen (initalizer)
EDIT
Okay? It works as expected on welcome screen to. I don't understand what I'm doing here that makes it do this? Can anyone offer a suggestion?
Re: Problem that has me going crazy.
Okay guys i seemed to have found a workaround. I noticed when running debugging and doing line by line when i called app restart it reran the formclosing event and i think thats what causing my problem. But i added an END in after the app restart. some reason the fist time through it gets to app restart and goes back up to start of sub, makes sense because cmd sen is basicly tell the form to close, and this time it goes to the end. somereason i still only end up with one intance now :) but not sure this is a goo dwork around. sinsee it ends up dong same task twice. so i hink i am going to try and redo the way the form handles closes
If any one has more suggestions let me know please
Re: [Somewhat Resolved] Problem that has me going crazy.
Instead of using End you could also use:
Re: [Somewhat Resolved] Problem that has me going crazy.
Quote:
Originally Posted by
Nightwalker83
Instead of using End you could also use:
That may work better to close it more peacefully. I was reading just a minutea go that i shouldn't use END because of messy closes? Anyways. I am going to try that. I am currently trying to....Well i'm not really sure lol :ehh:
Re: [Somewhat Resolved] Problem that has me going crazy.
vb Code:
If closer = 0 Then 'Sees if we are to the end of the wizard
Dim int As MsgBoxResult
int = MsgBox("If you close the configuration wizard you won't be able to use officeMonkey." + vbNewLine + vbNewLine + "Exit?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2 + MsgBoxStyle.Question, "OfficeMonkey Configuration")
If int = MsgBoxResult.Yes Then
e.Cancel = False
Else
e.Cancel = True
End If
ElseIf closer = 1 Then 'if we did then save settings, restart program
saveloadsettings(0)
My.Settings.setup = True
My.Settings.Save()
closer = 2
Application.Restart()
ElseIf closer = 2 Then
e.Cancel = False
End If
Currently working closeing method.
Going to try app exit now as nightwalker suggested
EDIT
Hmm, Well still nothing. I think i get why its doing it the way its doing it. Just thinking that i can prob just change closer to something other then whats in the statements skips the ifs all together 2nd time around so therefore it just closes
Re: [Somewhat Resolved] Problem that has me going crazy.
Code:
Private Sub Setup_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If closer = 0 Then 'Sees if we are to the end of the wizard
Dim int As MsgBoxResult
int = MsgBox("If you close the configuration wizard you won't be able to use officeMonkey." + vbNewLine + vbNewLine + "Exit?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2 + MsgBoxStyle.Question, "OfficeMonkey Configuration")
If int = MsgBoxResult.Yes Then
e.Cancel = False
Else
e.Cancel = True
End If
ElseIf closer = 1 Then 'if we did then save settings, restart program
saveloadsettings(0)
My.Settings.setup = True
My.Settings.Save()
closer = 2
Application.Restart()
End If
End Sub
Final code seems to work as needed. Marking thread as resolved. Thanks guys!
Re: [RESOLVED] Problem that has me going crazy.
Thread moved from 'VB6 and Earlier' forum to 'VB.Net' (VB2002 and later) forum
(thanks for letting us know Nightwalker83 :thumb: )