locked
COM Exception on AccountUpdated

    Question

  • Hello,

    I get a COM exception while accesing to CurrentNetwork property of MobileBroadbandAccount object after AccountUpdated event(Event get fired due to disconnection). 

    The exception description is below:

    Transition into COM context 0x1018f50 for this RuntimeCallableWrapper failed with the following error: An outgoing call cannot be made since the application is dispatching an input-synchronous call. (Exception from HRESULT: 0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL)). This is typically because the COM context 0x1018f50 where this RuntimeCallableWrapper was created has been disconnected or it is busy doing something else and cannot process the context transition. No proxy will be used to service the request on the COM component and calls will be made to the COM component directly. This may cause corruption or data loss. To avoid this problem, please ensure that all COM contexts/apartments/threads stay alive and are available for context transition, until the application is completely done with the RuntimeCallableWrappers that represents COM components that live inside them.

    I acces the Account object ,which is created in a non-UI thread, inside UI thread. If i dont access from the UI thread the exception does not get throwed. Why this happens? 

    Thanks

    Mehmet



    Wednesday, April 18, 2012 11:09 AM

Answers

  • Hi Mehmet,

    If you create an object in a UI thread you can’t access it from a non-UI thread and vice versa. Instead you have to use the pattern we have in the Mobile broadband account and device management sample at http://code.msdn.microsoft.com/windowsapps/Mobile-Broadband-API-Sample-7debc1ff, which is to have the callback function ask the dispatcher to do the work on the UI thread. The following is an excerpt from the C# sample.

    -Jack

                networkAccountWatcher.AccountAdded +=
                    (sender, args) =>
                    {
                        string message = "[accountadded] ";
    
                        try
                        {
                            message += args.NetworkAccountId;
    
                            var account = MobileBroadbandAccount.CreateFromNetworkAccountId(args.NetworkAccountId); 
    
                            message += ", service provider name: " + account.ServiceProviderName;
                        }
                        catch (Exception ex)
                        {
                            message += ex.Message;
                        }
    
                        DisplayWatcherOutputFromCallback(message);
                    };
    
         … 
    
            async void DisplayWatcherOutputFromCallback(string value)
            {
                await Dispatcher.RunAsync(
                    Windows.UI.Core.CoreDispatcherPriority.Normal,
                    () =>
                    {
                        WatcherOutput.Text = value;
                    });
            }
    

    Saturday, May 05, 2012 12:42 AM

All replies

  • I will look into this for you.

    Best Wishes - Eric

    Thursday, April 19, 2012 5:04 PM
    Moderator
  • Hi Mehmet,

    If you create an object in a UI thread you can’t access it from a non-UI thread and vice versa. Instead you have to use the pattern we have in the Mobile broadband account and device management sample at http://code.msdn.microsoft.com/windowsapps/Mobile-Broadband-API-Sample-7debc1ff, which is to have the callback function ask the dispatcher to do the work on the UI thread. The following is an excerpt from the C# sample.

    -Jack

                networkAccountWatcher.AccountAdded +=
                    (sender, args) =>
                    {
                        string message = "[accountadded] ";
    
                        try
                        {
                            message += args.NetworkAccountId;
    
                            var account = MobileBroadbandAccount.CreateFromNetworkAccountId(args.NetworkAccountId); 
    
                            message += ", service provider name: " + account.ServiceProviderName;
                        }
                        catch (Exception ex)
                        {
                            message += ex.Message;
                        }
    
                        DisplayWatcherOutputFromCallback(message);
                    };
    
         … 
    
            async void DisplayWatcherOutputFromCallback(string value)
            {
                await Dispatcher.RunAsync(
                    Windows.UI.Core.CoreDispatcherPriority.Normal,
                    () =>
                    {
                        WatcherOutput.Text = value;
                    });
            }
    

    Saturday, May 05, 2012 12:42 AM