Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidAccessViolation, other exceptions and slow down #12

Open
yarecky1 opened this issue Jun 29, 2019 · 3 comments
Open

InvalidAccessViolation, other exceptions and slow down #12

yarecky1 opened this issue Jun 29, 2019 · 3 comments

Comments

@yarecky1
Copy link

I discovered several issues using your library.

Situation 1:
I have a parent form with datagridview. Mouse doubleclick on datagridview row retrieves binded record and open new child form that presents details of this record. In that child form I can click Save button to save updated record in database, after which child form is closed/disposed and parent form updates datagridview. In child form before saving to database I do deepclone using your library:

I removed everything unrelated.

' Property in form
Property Audit As AuditDefinition

' Entrypoint to form
Public Sub New(audit As AuditDefinition)
    InitializeComponent()
    Me.Audit = audit
End Sub

' Somewhere in form I await saving function and if return true I close the form
If Await SaveInDbAsync() then Close()

' Saving in database
Private Async Function SaveInDbAsync() As Task(Of Boolean)
    ' Cloning Audit property in case of saving in database failure (then restore changed child properties)
    cAudit = Audit.DeepClone
   ' Rest of code
End Function

Child form is properly initialized and destroyed with using/end using clause from parent form.

Problem:
Each next time when child form in created (with new record Audit) and deepclone is performed it is slower and slower. Example times:
132 ms (first use of deepclone in application)
15 ms
25 ms
53 ms
163 ms
291 ms
569 ms

What do you think about it?

Situation 2:
Since I switch making clone objects from my implementation to yours my application started to close unexpectedly with many different exceptions, mainly System.AccessViolationException in random System.xxxx.dll libraries.

For example during debugging situation 1 above I made a simple loop making cloning 10 times the same object receiving each time the same time (opposite to situation above where time is longer and longer with each call) but just after exiting the loop application receives AccessViolationException.

Dim cAudit As AuditDefinition

For i = 0 To 9
    Debug.WriteLine(i)
    cAudit = Audit.DeepClone
Next

Result:

0
1
2
3
4
5
6
7
8
Exception thrown: 'System.Runtime.InteropServices.SEHException' in System.Windows.Forms.dll
9
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.

And debugger can move to next lines of code but soon application is closed with

Cross-thread operation not valid: Control '{0}' accessed from a thread other than the thread it was created on.
Or
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Exception occurs randomly after 4 to 9 cloning operations.
Moving operation to non-async function doesn't help.

What do you think about it?

@force-net
Copy link
Owner

It seems, Windows.Forms has a lot of internal dependencies and every deep clone (it a deep clone) tries to clone all related objects. Library trying to exclude some handles and native objects, which is dangerous to clone, but for Windows.Forms it seems it does not exclude it correctly.

I'll try to objects need to be excluded for this to avoid these problems. Thanks for issue.

@yarecky1
Copy link
Author

Hi, have you solve the issue?

@force-net
Copy link
Owner

Sorry, no. I have no time now to investigate problem. When I'll find any time to develop, I'll check this situation

force-net added a commit that referenced this issue Dec 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants