Hello,
I have a strange problem with my game for windows phone 8.1. I’ve integrated the vserv sdk for windows 8.1. I implemented the ads caching and showing in the App.xaml.cs in Visual Studio because it was the only way to get them working. First I tried to call the VServ’s cache ad method directly but I got the following exception:
Exception: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
at Windows.UI.Xaml.Controls.ProgressRing…ctor()
at com.vserv.windows.ads.wp81.VservAdView.InstantiateProgressRing()
at com.vserv.windows.ads.wp81.VservAdView.CacheAd()
at Template.App.SendShowAdMessage_showAdEvent()
at SendShowAdMessage.sendShowAdMessage()
at PresentAnimation.OnPresentPressed()
at PresentAnimation.$Invoke4(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
Then I changed the code like this to resolve the problems with the different threads:
appCallbacks.InvokeOnUIThread(new AppCallbackItem(() =>
{
adView.CacheAd();
}), false);
The full code is:
void initVServ()
{
if (!Configuration.adsRemoved())
{
Debug.WriteLine(“Ads Are not removed.”);
adView = new VservAdView();
adView.UX = VservAdUX.Interstitial;
adView.ZoneId = “XXXXXXXXXXX”;
//adView.TestDevice = new List() { “” };
adView.TimeOut = 10;
adView.RequestedOrientation = RequestedOrientation.Landscape;
isAdCached = false;
adView.DidCacheAd += adView_DidCacheAd;
adView.FailedToCacheAd += adView_FailedToCacheAd;
SendShowAdMessage.showAdEvent += SendShowAdMessage_showAdEvent;
}
}
void SendShowAdMessage_showAdEvent()
{
if (!Configuration.adsRemoved())
{
/appCallbacks.InvokeOnUIThread(new AppCallbackItem(() =>
{
adView.LoadAd();
}), true);/
if (isAdCached)
{
appCallbacks.InvokeOnUIThread(new AppCallbackItem(() =>
{
adView.ShowAd();
adView.CacheAd();
}), false);
}
else
{
appCallbacks.InvokeOnUIThread(new AppCallbackItem(() =>
{
try
{
adView.CacheAd();
}
catch (System.Exception e)
{
Debug.WriteLine(e.StackTrace);
Debug.WriteLine(e.Message);
}
}), false);
}
}
}
void adView_FailedToCacheAd(object sender, EventArgs e)
{
Debug.WriteLine(“Failed to Cache Ad - VServ”);
//adView.CacheAd();
isAdCached = false;
}
void adView_DidCacheAd(object sender, EventArgs e)
{
Debug.WriteLine(“Ad Cached - VServ”);
isAdCached = true;
}
Everything worked well that way except that I get AggregateException after the game returned from the UI thread and the cacheAd callback methods are called. When I sideload the app from visual studio there are no crashes because of this but after I download it from the windows phone store as beta app it crashes when I call the cacheAd method. I removed the VServ SDK, uploaded the game again and this time it doesn’t crashed. I wonder if there is something that I missed about the way I handle the thread changes. What could be the reason for the game to crash only when it’s downloaded from the store?
Thanks in advance!