C# Wpf Access Violation reading after creating second same type usercontrol

0

Hello I'm receiving this error:

Exception thrown at 0x756D17D2 (KernelBase.dll) in app.exe: 0xC0000005: Access violation reading location 0x00000000.

Disassembly look like this:

756D17D2  mov         ecx,dword ptr [esp+54h]

This error is thrown after creating second same type UserControl Code:

private void PrepareComplete()
    {
        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
         {
             ThingsToFixList.Children.Clear();
             MainWindow.AppWindow.DisableField();
             Settings.Completed = true;
             AfterField.Visibility = Visibility.Visible;
             MessageBox.Show(Settings.Delete.ToString());
             if (Settings.Delete)
             {
                 MessageBox.Show("Completed");
             }
             else
             {
                 if (Settings.Score > 0)
                 {
                     //using (CustomTemplate GT = new CustomTemplate())
                    // {
                         CustomTemplate GT = new CustomTemplate();
                         ThingsToFixList.Children.Add(GT);
                     //}
                }
             }
         }), DispatcherPriority.ContextIdle);
    }

This code is called 3 times first one pass as Settings.Delete is false, second time pass as Settings.Delete true, and third time is throws error.

Where is the problem I though usercontrol is still left in memory so I tried to include IDisposable with such method:

 public void Dispose()
    {
        GC.SuppressFinalize(this);
    }

It didnt help at all, as you can notice I tried with using but third time it failed again, also this usercontrol has multiple bindings could it be reason why its failing?

Edit 1: it throws error on this line:

CustomTemplate GT = new CustomTemplate();

Solution: Indeed it was binding problem, adding IsAsync=True Fixed the problem.

c#
wpf
asked on Stack Overflow Oct 22, 2018 by speed258 • edited Oct 22, 2018 by speed258

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0