none
Video Ads in C# UWP RRS feed

  • Question

  • This could be a an error due to my understating of UWP's deep concepts

    In my App I have two Projects :

    1>App_Code

    2>Bible_Lite

    For displaying Video Advertisements I have a class :

    namespace App_Code
    {
    public class VungleManager
    {
    
        VungleAd sdkInstance;
        bool adPlayable;
    
    
        public VungleManager()
        {
    
            //Obtain Vungle SDK instance
            sdkInstance = AdFactory.GetInstance("vungleTest");
    
    
        }
    
        public async void ShowMeAnAd()
        { 
            await sdkInstance.PlayAdAsync(new AdConfig());
        }
    
    }
    }

    Each time I call this from a backend of one of my pages:

    new App_Code.VungleManager().ShowMeAnAd();


    An Advertisement is displayed.

    However I want to display an Advertisement every 12 minutes.So I implemented this class :

    namespace App_Code
    {
    public static class TimeManager
    {
        private static Timer gAppTimer;
        private static object lockObject = new object();
    
        public static void StartTimer()
        {
            if (gAppTimer == null)
            {
                lock (lockObject)
                {
                    if (gAppTimer == null)
                    {
                        gAppTimer = new Timer(OnTimerTick, null, 6 * 1000, 12 * 60 * 1000);
                    }
                }
            }
        }
    
        public static void StopTimer()
        {
            if (gAppTimer != null)
            {
                lock (lockObject)
                {
                    if (gAppTimer != null)
                    {
                        gAppTimer.Change(Timeout.Infinite, Timeout.Infinite);
                        gAppTimer = null;
                    }
                }
            }
        }
    
        private static void OnTimerTick(object state)
        {
            new VungleManager().ShowMeAnAd();
        }
    
    
    }
    }

    In my App.xaml.cs I have called :

     App_Code.TimeManager.StartTimer();

    Now I expect this timer to play an ad every 12 minutes. However, I find that although ShowMeAnAd() runs properly but sdkInstance.adplayable is always false as a result of which my ad doesn't play.

    I think this is happening because my Timer is independent of the page I am working with in the second case.

    I just want an ad to be shown every 12 minutes. So, I implemented a kind of global timer for App. If you can suggest a better way of doing the same that did be welcome too

    You can find the sdk here

    UPDATE : what I have done is simply checked that if timer is ticked then display an advertisement ! I haven't notified any page which the user might be in during that time ! can you please shed some light ! I am trying this method because I don't want to have an adInstance in all of my Pages . It's my first try at ads

    • Moved by Barry Wang Thursday, April 21, 2016 4:45 AM ad
    Wednesday, April 20, 2016 4:04 PM