Beispiel #1
0
        private Task <T> RunWhenIdleWithTaskCompletionSource <T>(Func <T> callback, TaskCompletionSource <T> taskCompletionSource)
        {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            dispatcher.RunIdleAsync(new Windows.UI.Core.IdleDispatchedHandler(args =>
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            {
                taskCompletionSource.SetResult(callback());
            }));

            return(taskCompletionSource.Task);
        }
Beispiel #2
0
        public async Task DispatchIdleAsync(Action action, int delayms = 0)
        {
            await Task.Delay(delayms);

            var tcs = new TaskCompletionSource <object>();
            await dispatcher.RunIdleAsync(delegate
            {
                try { action(); tcs.TrySetResult(null); }
                catch (Exception ex) { tcs.TrySetException(ex); }
            });

            await tcs.Task;
        }
Beispiel #3
0
        public void InitLinphoneCore()
        {
            LinphoneManager.Instance.Core.ChatDatabasePath     = GetChatDatabasePath();
            LinphoneManager.Instance.Core.RootCa               = GetRootCaPath();
            LinphoneManager.Instance.Core.UserCertificatesPath = GetCertificatesPath();

            if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1))
            {
                AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged;
            }

            if (LinphoneManager.Instance.Core.VideoSupported())
            {
                DetectCameras();
            }
            LinphoneManager.Instance.Core.UsePreviewWindow(true);
            LinphoneManager.Instance.Core.SetUserAgent("LinphoneW10", Core.Version);
            if (LinphoneManager.Instance.Core.Config != null)
            {
                EnableLogCollection(
                    (LinphoneManager.Instance.Core.Config.GetInt("app", "LogLevel", (int)LogCollectionState.Disabled) == 1) ? true : false);
            }
            InitPushNotifications();
            isLinphoneRunning = true;
            TimeSpan period = TimeSpan.FromMilliseconds(20);

            ThreadPoolTimer.CreatePeriodicTimer((source) => {
                CoreDispatcher.RunIdleAsync((args) => {
                    Core.Iterate();
                });
            }, period);
        }
Beispiel #4
0
        public void InitLinphoneCore()
        {
            Core.LogLevel = OutputTraceLevel.Debug;

            LinphoneManager.Instance.Core.ChatDatabasePath = GetChatDatabasePath();
            LinphoneManager.Instance.Core.RootCa           = GetRootCaPath();

            if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract", 1))
            {
                AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged;
            }

            if (LinphoneManager.Instance.Core.IsVideoSupported)
            {
                DetectCameras();
            }

            LinphoneManager.Instance.Core.SetUserAgent("LinphoneW10", Core.Version);
            InitPushNotifications();
            isLinphoneRunning = true;
            TimeSpan period = TimeSpan.FromMilliseconds(20);

            ThreadPoolTimer.CreatePeriodicTimer((source) => {
                CoreDispatcher.RunIdleAsync((args) => {
                    Core.Iterate();
                });
            }, period);
        }
Beispiel #5
0
        public async Task DispatchIdleAsync(Action action)
        {
            var tcs = new TaskCompletionSource <object>();
            await _dispatcher.RunIdleAsync(delegate
            {
                try
                {
                    action();
                    tcs.TrySetResult(null);
                }
                catch (Exception ex)
                {
                    tcs.TrySetException(ex);
                }
            }).AsTask().ConfigureAwait(false);

            await tcs.Task.ConfigureAwait(false);
        }
Beispiel #6
0
 public FtpJobViewModel(FtpJob job, CoreDispatcher dispatcher)
 {
     this.job = job;
     Name     = job.Name;
     if (double.IsNaN(job.Progress))
     {
         Progress = 0;
         IsProgressIndeterminate = true;
     }
     else
     {
         Progress = job.Progress;
         IsProgressIndeterminate = false;
     }
     UpdateStatusFromJob(job);
     {
         job.ProgressChanged += async(sender, e) =>
         {
             await dispatcher.RunIdleAsync(e1 =>
             {
                 if (double.IsNaN(job.Progress))
                 {
                     IsProgressIndeterminate = true;
                 }
                 else
                 {
                     IsProgressIndeterminate = false;
                     Progress = job.Progress;
                 }
             });
         };
     }
     {
         job.StatusChanged += async(sender, e) =>
         {
             await dispatcher.RunIdleAsync(e1 =>
             {
                 UpdateStatusFromJob(job);
             });
         };
     }
 }
Beispiel #7
0
        /// <summary>
        /// Runs the handler at idle priority.
        /// </summary>
        /// <param name="dispatcher">
        /// The <see cref="CoreDispatcher"/> that will run the handler.
        /// </param>
        /// <param name="handler">
        /// The handler to run.
        /// </param>
        /// <returns>
        /// The <see cref="IAsyncAction"/> that represents the operation.
        /// </returns>
        static public IAsyncAction RunIdleAsync(this CoreDispatcher dispatcher, DispatchedHandler handler)
        {
            // Validate
            if (dispatcher == null)
            {
                throw new ArgumentNullException("dispatcher");
            }

            // Run
            return(dispatcher.RunIdleAsync((e) => { handler(); }));
        }
        public async Task DispatchIdleAsync(Action action, int delayms = 0)
        {
            if (this.dispatcher.HasThreadAccess)
            {
                if (delayms > 0)
                {
                    await Task.Delay(delayms).ConfigureAwait(true);
                }
                action();
            }
            else
            {
                if (delayms > 0)
                {
                    await Task.Delay(delayms).ConfigureAwait(false);
                }
                var tcs = new TaskCompletionSource <object>();
                await dispatcher.RunIdleAsync(delegate
                {
                    try
                    {
                        action();
                        tcs.TrySetResult(null);
                    }
                    catch (Exception ex)
                    {
                        tcs.TrySetException(ex);
                    }
                });

                await tcs.Task.ConfigureAwait(false);
            }
        }
Beispiel #9
0
        void WaitForIdleDispatcher()
        {
            bool           isDispatcherIdle    = false;
            AutoResetEvent shouldContinueEvent = new AutoResetEvent(false);

            while (!isDispatcherIdle)
            {
                IAsyncAction action = m_coreDispatcher.RunIdleAsync(new IdleDispatchedHandler((IdleDispatchedHandlerArgs args) =>
                {
                    isDispatcherIdle = args.IsDispatcherIdle;
                }));

                action.Completed = new AsyncActionCompletedHandler((IAsyncAction, AsyncStatus) =>
                {
                    shouldContinueEvent.Set();
                });

                shouldContinueEvent.WaitOne(10000);
            }
        }
        void PopulateData(IEnumerable <TaskItem> entries)
        {
            dispatcher.RunIdleAsync(delegate {
                //
                // Set all the news items
                //
                Items = new ObservableCollection <TaskViewModel>(
                    from e in entries
                    select new TaskViewModel(e));

                //
                // Update the properties
                //
                OnPropertyChanged("Items");

                ListVisibility   = Items.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
                NoDataVisibility = Items.Count == 0 ? Visibility.Visible : Visibility.Collapsed;

                OnPropertyChanged("ListVisibility");
                OnPropertyChanged("NoDataVisibility");
                OnPropertyChanged("IsUpdating");
                OnPropertyChanged("UpdatingVisibility");
            });
        }