Click here to Skip to main content
15,793,452 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Main screen opens a dialog window (win) upon button click.

Private Sub myBtn_click(sender As Object, e As RoutedEventArgs) Handles myBtn.Click
    Dim w As New win
    w.Owner = Me
    Dim d As DataRowView
    If w.ShowDialog = True Then
        'Do something
    End If
    w = Nothing
    d = Nothing
End Sub

Win opens and does stuff with two datasets it creates. Win's WindowStyle was a SingleBorderWindow. So it had the standard tools in the upper right for maximizing, minimizing, and closing.

It has a button for Save and Cancel.

Clicking Save and Cancel seem to work fine.

However, when I close win using the standard window close tool in the upper left, SOMETIMES it would work fine and other times win's would turn BLACK and would just hang there until I minimized it. The calling window went back to do its thing.

If I make win's WindowStyle None then the user has no standard window close tool to make this annoyance. But that's crazy.

It must be that I'm not closing the window and releasing the resources properly, with Garbage Collection or Mr. Disposal getting in the way.

How can I make it work properly?

Here's code for win. Thanks

Public Class win
    Private ds1 As New DataSet
    Private ds2 As New DataSet

    Private Sub btnSave_Click(sender As Object, e As RoutedEventArgs) Handles btnSave.Click
        Me.DialogResult = True
    End Sub

    Private Sub btnCancel_Click(sender As Object, e As RoutedEventArgs) Handles btnCancel.Click
    End Sub

    Private Sub CancelMe()
        Me.DialogResult = False
    End Sub

    Private Sub win_Closing(sender As Object, e As ComponentModel.CancelEventArgs) Handles Me.Closing
        ds1 = Nothing
        ds2 = Nothing
    End Sub

End Class
Updated 5-Aug-13 17:16pm
Sergey Alexandrovich Kryukov 5-Aug-13 16:10pm    
I don't think we have enough information to reproduce the problem. Could you possibly make a highly simplified single-file complete example which still reproduces the problem?
Member 10191023 5-Aug-13 17:07pm    
I don't know how to make it any simpler other than creating a WPF application with a button that you click on, which handles myBtn.Click, as above.

If nobody can repoduce the problem then let me ask a different question:

Am I opening up the dialog window the right way?

Am I closing the dialog window the right way and disposing of the objects properly?

Is win_Closing the right windows event for doing this? Does the native windows closing tool in the upper right corner doing something that interferes with what I do in the win-Closing event?

I'm using VS 2012 and this occurs when I run the app in debug mode. I do have a bunch of datasets open in memory.

Sergey Alexandrovich Kryukov 6-Aug-13 0:37am    
No. Who is "nobody"?! The project is only yours at this time. You can reproduce the problem on a simple but complete sample project, you probably just don't want to take the labor of doing it.
You are disposing only two datasets, which have nothing to do with your "ugly black screen". It's unclear to me why do you use datasets like that. You don't show any use of them. Anyway, you can always simplify the application down and see what happens. If you do, chances are, you can find out the root cause of the problem by yourself...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900