Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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.

Posted

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

Posted
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???
Posted (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 by Voca
Posted

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

Posted

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.

Posted

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

.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?
Posted
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?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...