当前位置: 首页>>代码示例>>C#>>正文


C# TimeoutHelper.Begin方法代码示例

本文整理汇总了C#中TimeoutHelper.Begin方法的典型用法代码示例。如果您正苦于以下问题:C# TimeoutHelper.Begin方法的具体用法?C# TimeoutHelper.Begin怎么用?C# TimeoutHelper.Begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeoutHelper的用法示例。


在下文中一共展示了TimeoutHelper.Begin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartAd

 /// <summary>
 /// Tells the ad to start.
 /// </summary>
 /// <param name="ad">The ad creative that should start playing</param>
 /// <param name="userState">A user state associated with this ad. This will be included with the various events associated with this ad.</param>
 public void StartAd(ActiveCreative ad, object userState)
 {
     TimeoutHelper<EventArgs> timeoutHandler = new TimeoutHelper<EventArgs>();
     ad.Player.AdStarted += timeoutHandler.Complete;
     EventHandler<VpaidMessageEventArgs> failHandler = (s, e) => timeoutHandler.Failed(new Exception(e.Message));
     ad.Player.AdError -= player_AdError;
     ad.Player.AdError += failHandler;
     timeoutHandler.Completed += (s, e) =>
     {
         ad.Player.AdStarted -= timeoutHandler.Complete;
         ad.Player.AdError -= failHandler;
         if (e.Error == null)
         {
             ad.Player.AdError += player_AdError;
             player_AdStarted(ad.Player, e.Result);
         }
         else
             if (AdStartFailed != null) AdStartFailed(this, new ActiveCreativeEventArgs(ad, userState));
     };
     timeoutHandler.Begin(() =>
     {
         try
         {
             ad.Player.StartAd();
         }
         catch (Exception ex)
         {
             OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.StartAd Exception: " + ex.Message));
             throw ex;
         }
     }, AdStartTimeout);
 }
开发者ID:Ginichen,项目名称:Silverlight-Player-for-PlayReady-with-Token-Auth,代码行数:37,代码来源:VpaidController.cs

示例2: StopAd

 /// <summary>
 /// Stops the ad.
 /// </summary>
 /// <param name="ad">The ad creative that should stop playing</param>
 /// <param name="userState">A user state associated with this ad. This will be included with the various events associated with this ad.</param>
 void StopAd(ActiveCreative ad, object userState)
 {
     TimeoutHelper<EventArgs> timeoutHandler = new TimeoutHelper<EventArgs>();
     ad.Player.AdStopped -= player_AdStopped;    // temporarily unhook this event. Instead we will use our timeout handler to help trap for it.
     ad.Player.AdStopped += timeoutHandler.Complete;
     EventHandler<VpaidMessageEventArgs> failHandler = (s, e) => timeoutHandler.Failed(new Exception(e.Message));
     ad.Player.AdError -= player_AdError;
     ad.Player.AdError += failHandler;
     timeoutHandler.Completed += (s, e) =>
     {
         ad.Player.AdStopped += player_AdStopped;    // hook up the event again
         ad.Player.AdStopped -= timeoutHandler.Complete;
         ad.Player.AdError -= failHandler;
         if (e.Error == null)
         {
             ad.Player.AdError += player_AdError;
             player_AdStopped(ad.Player, e.Result);
         }
         else
             if (AdStopFailed != null) AdStopFailed(this, new ActiveCreativeEventArgs(ad, userState));
     };
     timeoutHandler.Begin(() =>
     {
         try
         {
             ad.Player.StopAd();
         }
         catch (Exception ex)
         {
             OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.StopAd Exception: " + ex.Message));
             throw ex;
         }
     }, AdStopTimeout);
 }
开发者ID:Ginichen,项目名称:Silverlight-Player-for-PlayReady-with-Token-Auth,代码行数:39,代码来源:VpaidController.cs

示例3: LoadAd

        /// <summary>
        /// Loads a creative. This causes VPAID.InitAd to execute.
        /// </summary>
        /// <param name="ad">The creative to load</param>
        /// <param name="bitrate">The current bitrate of the player. This is passed onto the VPAID player which can use it to initialize itself.</param>
        /// <param name="userState">A user state associated with this ad. This will be included with the various events associated with this ad.</param>
        public void LoadAd(ActiveCreative ad, int bitrate, object userState)
        {
            if (!activeAds.ContainsKey(ad.Player))
            {
                activeAds.Add(ad.Player, ad);
                HookupPlayer(ad.Player);
            }

            userStates.Add(ad, userState);

            Size adContainerSize = ad.Target.Size;

            TimeoutHelper<EventArgs> InitAdTimeoutHandler = new TimeoutHelper<EventArgs>();
            ad.Player.AdLoaded += InitAdTimeoutHandler.Complete;
            EventHandler<VpaidMessageEventArgs> failHandler = (s, e) => InitAdTimeoutHandler.Failed(new Exception(e.Message));
            ad.Player.AdError -= player_AdError;
            ad.Player.AdError += failHandler;

            InitAdTimeoutHandler.Completed += (s, e) =>
                {
                    ad.Player.AdLoaded -= InitAdTimeoutHandler.Complete;
                    ad.Player.AdError -= failHandler;
                    if (e.Error == null)
                    {
                        ad.Player.AdError += player_AdError;
                        player_AdLoaded(ad.Player, e.Result);
                    }
                    else
                        if (AdLoadFailed != null) AdLoadFailed(this, new ActiveCreativeEventArgs(ad, userState));
                };
            InitAdTimeoutHandler.Begin(() =>
            {
                try
                {
                    ad.Player.InitAd(
                        adContainerSize.Width,
                        adContainerSize.Height,
#if !WINDOWS_PHONE && !FULLSCREEN
                        Application.Current.Host.Content.IsFullScreen ? "fullscreen" : "normal",
#else
 "normal",
#endif
 bitrate,
                        ad.Source.MediaSource,
                        ad.Source.ExtraInfo);
                }
                catch (Exception ex)
                {
                    OnLog(new ActiveCreativeLogEventArgs(ad, "VPAID.AdInit Exception: " + ex.Message));
                    throw ex;
                }
            }, AdInitTimeout);
        }
开发者ID:Ginichen,项目名称:Silverlight-Player-for-PlayReady-with-Token-Auth,代码行数:59,代码来源:VpaidController.cs


注:本文中的TimeoutHelper.Begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。