public ListViewModel(IPageDialogService dialogService, INavigationService navigationService) { var ipaddressService = Xamarin.Forms.DependencyService.Get <IIPAddressManager>(); string ipaddress = ipaddressService.GetIPAddress(); string[] gateWayIpAddress = ipaddressService.GetGateWayAddress(); if (!string.IsNullOrEmpty(ipaddress)) { UserDetails = string.Format("IP Address: {0} - Gateway Address: {1}", ipaddress, string.Join(".", gateWayIpAddress)); } this.dialogService = dialogService; this.navigationService = navigationService; AvailableDevices = new ObservableCollection <User>(); NetworkHandler.CallBackForView = CallBackForCallStatus; NetworkHandler.CallBackForUserDetails = CallBackForUserDetails; // start the device discovery and initialize the reciever Task.Factory.StartNew(() => { NetworkHandler.DiscoverDevices(); }, new System.Threading.CancellationToken(false), TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext()); //.ConfigureAwait(false); // move initiate reciever to App.cs in a long running task, to keep listening for the incoming connections, even // when the app is in the background // this will initiate the reciever using an android service //BackgroundService.Start(); InitiateReciever(); }
public void RefreshDevices() { AvailableDevices = new ObservableCollection <User>(); Task.Factory.StartNew(() => { NetworkHandler.DiscoverDevices(); }, new System.Threading.CancellationToken(false), TaskCreationOptions.AttachedToParent, TaskScheduler.FromCurrentSynchronizationContext()); //.ConfigureAwait(false); }