0

So as the title says I don't know why there is this "ObejectDisposedException". It is occuring when the download has finished during the last Call of "OnDownloadUpdated(..)".

The line "this.Invoke(..)" throws the exception.

    ChromiumWebBrowser browser;

    public frmRocketPluginDownload()
    {
        InitializeComponent();

        var settings = new CefSettings();
        settings.BrowserSubprocessPath = @"x86\CefSharp.BrowserSubprocess.exe";


        Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);

        browser = new ChromiumWebBrowser("");
        browser.Dock = DockStyle.Fill;
        browser.AddressChanged += Browser_AddressChanged;
        browser.DownloadHandler = this;


        panelBody.Controls.Add(browser);
    }


    public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
    {
        this.Invoke((MethodInvoker)delegate
        {
            if (downloadItem.PercentComplete == 100)
            {
                this.Show();
            }
        });
    }
IchBestäube
  • 61
  • 3
  • 11

1 Answers1

0

It is race condition. When Form is closing during OnDownloadUpdated (which I assume is called from other thread) then is up to which operation ends first: Form disposing or OnDownloadUpdated. To prevent this check in Form.Closing event if your method has ended, otherwise set Closing.Cancel to true to prevent closing the Form.

Michał Zych
  • 149
  • 1
  • 8
  • The form is hidden during download and I am not closing it anywhere in my code so I think this is not the problem. – IchBestäube Jan 30 '17 at 11:20
  • If the line of the exception is "this.Invoke(..)" then it means your form has been disposed. Now you need to figure out why it has been disposed. Whatever object is on the error line that throws that Exception has had its .Dispose() method called. Try to NOT hide your form during the download and I assume you quickly will discover if the form is the problem or not. – Wolf5 Jan 30 '17 at 11:26
  • Thank you. By removing the "this.visible = false" it got solved but I don't really understand why this line was so problematic. – IchBestäube Jan 30 '17 at 12:54