CookieMonster24 Posted November 25, 2003 Posted November 25, 2003 When i create a form, i call the form using showdialog. in the form i have a few buttons, yes, no and cancel. if i select yes, the form has a delay in trying to close. e.g. i have result = formToOpen.showdialog(me) if result = dialogresult.yes then 'i do whatever is needed to save data elseif result = dialogresult.no then 'i do nothing and close the form end if formToOpen.dispose is there any way to speed up the closing of the form when Yes is selected? i have several functions being called in the first if statement, but i would hope that the form could be closed and then the functions ran. is this possible? Quote
Administrators PlausiblyDamp Posted November 25, 2003 Administrators Posted November 25, 2003 (edited) Is there any code if the event handler for the yes button? edit: really bad typo Edited November 26, 2003 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
CookieMonster24 Posted November 25, 2003 Author Posted November 25, 2003 There's quite a bit of code to run if the yes button has been pressed. i also set something up like this: result = formToOpen.showDialog(Me) If result = DialogResult.Yes Then yesEntered = True 'startTimer() ElseIf result = DialogResult.No Then 'startTimer() end if if yesEntered = true then ...... end if i thought, perhaps that would make a difference, but it doesn't. Quote
Engine252 Posted November 26, 2003 Posted November 26, 2003 way don't you do wath you say you want to do close the form and then do the saving data if yourform.showdialog = dialogresult.yes then yourform.close save data else yourform.close end if Quote
CookieMonster24 Posted November 26, 2003 Author Posted November 26, 2003 i've tried that, doesn't work. what currently happens is that i'll press the button, part of the form will disappear and i'll still get a bit showing, it'll do the save, and when that's completed the form will close completely. all i want to do is to just get rid of the form and put an hourglass up fairly quick, but the saving the data is slowing things down. it's like i have to save the data before the form can be closed, even though i have made the call to close the form. why is this happening??? Quote
feurich Posted November 27, 2003 Posted November 27, 2003 Do you need to get data that is linked to the form? Quote Trust the Universe
Voca Posted November 27, 2003 Posted November 27, 2003 (edited) If I did understand it right you want the WIndow to disappear and then do something else? Why not try this bit of code instead: Dim MyForm as New WhatEverForm MyForm.ShowDialog Dim result as Dialogresult = MyForm.DialogResult Select Case true case result = DialogResult.Yes me.Cursor = Cursors.Wait me.DoWhateverIWant() me.Cursor = Cursors.Default case result = DilaogResult.No ... case else ... End select The bit with MyForm.Close has to be put into the dialogs's Button_Click-Event. Your instance of the form stores the dialogresult If the dialog includes also data you want to save, I'd say you will need 2 methods for saving . Voca (If I`ve mixed up VB.net with some other language, please let me know, I'll edit my code, then) Edited November 27, 2003 by Voca Quote
Engine252 Posted November 29, 2003 Posted November 29, 2003 create a thread that executes the saving of that data or wathever you want to do before closing that form ex: dim SavingThread as new threading.thread (addresoff SavingFunction) then in the closing of the form do if result = yes then SavingThread.start form.close else blablabla end if well you know the rest that should do the trick if it doesn't well it will so ... hope it help bui Quote
CookieMonster24 Posted December 1, 2003 Author Posted December 1, 2003 well....that kinda works. i can start my thread, but would i need to join or somehow stop the thread. when i save there is no infinite loop, and if i use a join, it still is slow. if i don't use join, there is no slow down. this is what i currently have. If result = DialogResult.Yes Then confirmDialog.disableTimer() confirmDialog.Dispose() 'saveProc() saveThread = New System.Threading.Thread(AddressOf saveProc) saveThread.IsBackground = True saveThread.Start() saveThread.Join() saveThread = Nothing else..... not sure if this right. i've never used threads before. Quote
AndreRyan Posted December 2, 2003 Posted December 2, 2003 You can probably just use the close method without the threads: '... Me.close() Application.DoEvents() 'This will allow Windows to wipe the form out 'Save Everything ... If you want to use the threading method: Private saveThread As Thread Public Sub saveProc() Try 'Save Everything saveThread.Abort() 'The thread will be shutdown when it gets to here but 'it risks crashing if the thread object is accessed on another thread 'There is some failsafe attribute that I don't remeber though Catch : End Try End Sub Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
CookieMonster24 Posted December 2, 2003 Author Posted December 2, 2003 Thanks! your first suggestion worked. exactly what i was looking for Quote
PurpleMonkey Posted December 3, 2003 Posted December 3, 2003 How does application.doevents work? the explanation i found in the index seems confusing. can doevents be used if they are using showdialog? it seems like you were using it for form.show. what happened to the dispose of the dialog? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.