System.Runtime.InteropServices.COMException: 'An outgoing call cannot be made since the application is dispatching an input-synchronous call. (Exception from HRESULT: 0x8001010D

babukumarasamy 81 Reputation points
2021-02-02T13:38:23.24+00:00

Changing the wbbrowser width after network connect or disconnct throws the error "System.Runtime.InteropServices.COMException: 'An outgoing call cannot be made since the application is dispatching an input-synchronous call. (Exception from HRESULT: 0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL))'"

63151-image.png

Attached the source code. Please do the needful.

using iTuner;  
using System;  
using System.Windows.Forms;  
  
namespace NetworkConnectError  
{  
    public partial class Form1 : Form  
    {  
        public Form1()  
        {  
            InitializeComponent();  
  
            DisposeBrowser();  
            WindowState = FormWindowState.Minimized;  
            this.Visible = false;  
  
        }  
  
        private void DisposeBrowser()  
        {  
            try  
            {  
                if (webBrowser1 == null || webBrowser1.IsDisposed) return;  
  
                webBrowser1.Navigate(new Uri("about:blank"));//TRK - 107  
                webBrowser1.Stop();  
  
            }  
            catch (Exception ex)  
            {  
                MessageBox.Show(ex.Message);  
            }  
        }  
  
        private void NetworkAvailabilityChanged(object sender, NetworkStatusChangedArgs e)  
        {  
            try  
            {  
                if (e.IsAvailable)  
                {  
  
                    System.Threading.Thread myThread = new System.Threading.Thread(new System.Threading.ThreadStart(Client));  
                    myThread.Start();  
                }  
            }  
            catch (Exception ex)  
            {  
                MessageBox.Show(ex.Message);  
            }  
        }  
  
  
        private void Client()  
        {  
            //WindowState = FormWindowState.Maximized;  
            webBrowser1.Left = 0;  
            webBrowser1.Top = 0;  
  
            Screen scr = Screen.PrimaryScreen;  
            webBrowser1.Width = scr.Bounds.Width;  
            int iHeight = scr.Bounds.Height;  
            iHeight = iHeight + 50;  
            webBrowser1.Height = iHeight;  
        }  
  
        private void Form1_Load(object sender, EventArgs e)  
        {  
            NetworkStatus.AvailabilityChanged += new NetworkStatusChangedHandler(NetworkAvailabilityChanged);  
        }  
    }  
}  
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,828 questions
0 comments No comments
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,611 Reputation points
    2021-02-03T06:03:55.23+00:00

    Hi babukumarasamy-5694,
    Based on your code, this may be a threading problem.
    And I suggest you use a BackgroundWorker which makes thread-safe calls to Windows Forms controls.
    Here is a code example you can refer to.

    private void Form1_Load(object sender, EventArgs e)  
    {  
    backgroundWorker1.RunWorkerAsync();  
    }  
      
    private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)  
    {  
        webBrowser1.Left = 0;  
        webBrowser1.Top = 0;  
        Screen scr = Screen.PrimaryScreen;  
        webBrowser1.Width = scr.Bounds.Width;  
        int iHeight = scr.Bounds.Height;  
        iHeight = iHeight + 50;  
        webBrowser1.Height = iHeight;  
    }  
    

    Here is a related document you can refer to.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful