當前位置: 首頁>>代碼示例>>C#>>正文


C# DeviceWatcher.Start方法代碼示例

本文整理匯總了C#中Windows.Devices.Enumeration.DeviceWatcher.Start方法的典型用法代碼示例。如果您正苦於以下問題:C# DeviceWatcher.Start方法的具體用法?C# DeviceWatcher.Start怎麽用?C# DeviceWatcher.Start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.Devices.Enumeration.DeviceWatcher的用法示例。


在下文中一共展示了DeviceWatcher.Start方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ExternalDeviceService

 public ExternalDeviceService()
 {
     _deviceWatcher = DeviceInformation.CreateWatcher(DeviceClass.PortableStorageDevice);
     _deviceWatcher.Added += DeviceAdded;
     _deviceWatcher.Removed += DeviceRemoved;
     _deviceWatcher.Start();
 }
開發者ID:robUx4,項目名稱:vlc-winrt,代碼行數:7,代碼來源:ExternalDeviceService.cs

示例2: UsbScopeDevice

 public UsbScopeDevice()
 {
     var usbScopeSelector = HidDevice.GetDeviceSelector(UsagePage, UsageId, Vid, Pid);
     ScopeDeviceWatcher = DeviceInformation.CreateWatcher(usbScopeSelector);
     ScopeDeviceWatcher.Added += new TypedEventHandler<DeviceWatcher, DeviceInformation>(OnDeviceAdded);
     ScopeDeviceWatcher.Removed += new TypedEventHandler<DeviceWatcher, DeviceInformationUpdate>(OnDeviceRemoved);
     ScopeDeviceWatcher.Start();
 }
開發者ID:gazzyt,項目名稱:GaryScope,代碼行數:8,代碼來源:UsbScopeDevice.cs

示例3: Scenario4_BackgroundProximitySensor

        public Scenario4_BackgroundProximitySensor()
        {
            this.InitializeComponent();

            watcher = DeviceInformation.CreateWatcher(ProximitySensor.GetDeviceSelector());
            watcher.Added += OnProximitySensorAdded;
            watcher.Start();
        }
開發者ID:C-C-D-I,項目名稱:Windows-universal-samples,代碼行數:8,代碼來源:Scenario4_BackgroundProximitySensor.xaml.cs

示例4: NetworkPresenter

 public NetworkPresenter()
 {
     WiFiAdaptersWatcher = DeviceInformation.CreateWatcher(WiFiAdapter.GetDeviceSelector());
     WiFiAdaptersWatcher.EnumerationCompleted += AdaptersEnumCompleted;
     WiFiAdaptersWatcher.Added += AdaptersAdded;
     WiFiAdaptersWatcher.Removed += AdaptersRemoved;
     WiFiAdaptersWatcher.Start();
 }
開發者ID:MicrosoftEdge,項目名稱:WebOnPi,代碼行數:8,代碼來源:NetworkPresenter.cs

示例5: OnNavigatedTo

 protected async override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     watcher = DeviceInformation.CreateWatcher(ProximitySensor.GetDeviceSelector());
     watcher.Added += OnProximitySensorAdded;
     watcher.Start();
     timer = new Timer(TimerCallBack, null, Timeout.Infinite, 4000);
     await InitializeCameraAsync();
 }
開發者ID:UWPanda,項目名稱:BemeRecorder,代碼行數:9,代碼來源:MainPage.xaml.cs

示例6: HidGamepad

 static HidGamepad()
 {
     var deviceSelector = HidDevice.GetDeviceSelector(0x01, 0x05);
     _watcher = DeviceInformation.CreateWatcher(deviceSelector);
     _watcher.Added += HandleDeviceAdded;
     _watcher.Updated += HandleDeviceUpdated;
     _watcher.Removed += HandleDeviceRemoved;
     _watcher.EnumerationCompleted += HandleEnumerationCompleted;
     _watcher.Start();
 }
開發者ID:bricelam,項目名稱:HidGamepad,代碼行數:10,代碼來源:HidGamepad.cs

示例7: StartListeningForSerialPortChanges

        private void StartListeningForSerialPortChanges()
        {
            serialPortWatcher = DeviceInformation.CreateWatcher(SerialDevice.GetDeviceSelector());

            serialPortWatcher.Added += SerialPortWatcher_Added;
            serialPortWatcher.Removed += SerialPortWatcher_Removed;
            serialPortWatcher.Updated += SerialPortWatcher_Updated;

            serialPortWatcher.Start();
        }
開發者ID:moszinet,項目名稱:MosziNet.XBee,代碼行數:10,代碼來源:XBeeSerialPort.cs

示例8: ConnectedDevicePresenter

    public ConnectedDevicePresenter(CoreDispatcher dispatcher)
    {
      this.dispatcher = dispatcher;

      usbConnectedDevicesWatcher = DeviceInformation.CreateWatcher(usbDevicesSelector);
      usbConnectedDevicesWatcher.EnumerationCompleted += DevicesEnumCompleted;
      usbConnectedDevicesWatcher.Updated += DevicesAdded;
      usbConnectedDevicesWatcher.Removed += DevicesRemoved;
      usbConnectedDevicesWatcher.Start();
    }
開發者ID:SteamMaker,項目名稱:haxc,代碼行數:10,代碼來源:ConnectedDevicePresenter.cs

示例9: Scenario2_Polling

        public Scenario2_Polling()
        {
            String customSensorSelector = "";

            this.InitializeComponent();

            customSensorSelector = CustomSensor.GetDeviceSelector(GUIDCustomSensorDeviceVendorDefinedTypeID);
            watcher = DeviceInformation.CreateWatcher(customSensorSelector);
            watcher.Added += OnCustomSensorAdded;
            watcher.Start();
        }
開發者ID:t-angma,項目名稱:Windows-universal-samples,代碼行數:11,代碼來源:scenario2_polling.xaml.cs

示例10: Blink1

        static Blink1()
        {
            var selector = HidDevice.GetDeviceSelector(0xFF00, 0x0001, 0x27B8, 0x01ED);

            _watcher = DeviceInformation.CreateWatcher(selector);
            _watcher.Added += HandleDeviceAdded;
            _watcher.Updated += HandleDeviceUpdated;
            _watcher.Removed += HandleDeviceRemoved;
            _watcher.EnumerationCompleted += HandleEnumerationCompleted;
            _watcher.Start();
        }
開發者ID:bricelam,項目名稱:ThingM.Blink1,代碼行數:11,代碼來源:Blink1.cs

示例11: btnWatcher_Click

        private void btnWatcher_Click(object sender, RoutedEventArgs e)
        {
            if (_fWatcherStarted == false)
            {
                _publisher.Start();

                if (_publisher.Status != WiFiDirectAdvertisementPublisherStatus.Started)
                {
                    rootPage.NotifyUser("Failed to start advertisement.", NotifyType.ErrorMessage);
                    return;
                }

                DiscoveredDevices.Clear();
                rootPage.NotifyUser("Finding Devices...", NotifyType.StatusMessage);

                String deviceSelector = WiFiDirectDevice.GetDeviceSelector(
                    Utils.GetSelectedItemTag<WiFiDirectDeviceSelectorType>(cmbDeviceSelector));

                _deviceWatcher = DeviceInformation.CreateWatcher(deviceSelector, new string[] { "System.Devices.WiFiDirect.InformationElements" });

                _deviceWatcher.Added += OnDeviceAdded;
                _deviceWatcher.Removed += OnDeviceRemoved;
                _deviceWatcher.Updated += OnDeviceUpdated;
                _deviceWatcher.EnumerationCompleted += OnEnumerationCompleted;
                _deviceWatcher.Stopped += OnStopped;

                _deviceWatcher.Start();

                btnWatcher.Content = "Stop Watcher";
                _fWatcherStarted = true;
            }
            else
            {
                _publisher.Stop();

                btnWatcher.Content = "Start Watcher";
                _fWatcherStarted = false;

                _deviceWatcher.Added -= OnDeviceAdded;
                _deviceWatcher.Removed -= OnDeviceRemoved;
                _deviceWatcher.Updated -= OnDeviceUpdated;
                _deviceWatcher.EnumerationCompleted -= OnEnumerationCompleted;
                _deviceWatcher.Stopped -= OnStopped;

                _deviceWatcher.Stop();

                rootPage.NotifyUser("Device watcher stopped.", NotifyType.StatusMessage);
            }
        }
開發者ID:polarapfel,項目名稱:Windows-universal-samples,代碼行數:49,代碼來源:Scenario2_Connector.xaml.cs

示例12: Scenario2_Polling

        public Scenario2_Polling()
        {
            String customSensorSelector = "";

            this.InitializeComponent();

            customSensorSelector = CustomSensor.GetDeviceSelector(GUIDCustomSensorDeviceVendorDefinedTypeID);
            watcher = DeviceInformation.CreateWatcher(customSensorSelector);
            watcher.Added += OnCustomSensorAdded;
            watcher.Start();

            // Register to be notified when the user disables access to the custom sensor through privacy settings.
            deviceAccessInformation = DeviceAccessInformation.CreateFromDeviceClassId(GUIDCustomSensorDeviceVendorDefinedTypeID);
            deviceAccessInformation.AccessChanged += new TypedEventHandler<DeviceAccessInformation, DeviceAccessChangedEventArgs>(OnAccessChanged);
        }
開發者ID:RasmusTG,項目名稱:Windows-universal-samples,代碼行數:15,代碼來源:Scenario2_Polling.xaml.cs

示例13: WatchDevices_Click

        //public ObservableCollection<clsDevType> DevTypes = new ObservableCollection<clsDevType>();

        async void WatchDevices_Click(object sender, RoutedEventArgs eventArgs)
        {
            if (watcher != null)
            {
                watcher = null;
            }
            count = 0; 
            isEnumerationComplete = false;
            StopStatus = null;
            //DeviceInterfacesOutputList.Items.Clear();

            try
            {
                dispatcher = Window.Current.CoreWindow.Dispatcher;
                watcher = DeviceInformation.CreateWatcher();
                // Add event handlers
                watcher.Added += watcher_Added;
                watcher.Removed += watcher_Removed;
                watcher.Updated += watcher_Updated;
                watcher.EnumerationCompleted += watcher_EnumerationCompleted;
                watcher.Stopped += watcher_Stopped;
                watcher.Start();
                OutputText.Text = "Enumeration started.";

                this.btnWatchDevices.IsEnabled = false;
                this.btnStop.IsEnabled = !(this.btnWatchDevices.IsEnabled);


            }
            catch (ArgumentException)
            {
                //The ArgumentException gets thrown by FindAllAsync when the GUID isn't formatted properly
                //The only reason we're catching it here is because the user is allowed to enter GUIDs without validation
                //In normal usage of the API, this exception handling probably wouldn't be necessary when using known-good GUIDs 
                OutputText.Text = "Caught ArgumentException. Failed to create watcher.";
            }
        }
開發者ID:djaus2,項目名稱:WindowsDevices,代碼行數:39,代碼來源:MainPage.xaml.cs

示例14: InitDiscovery

        private void InitDiscovery()
        {

            discoverTask = null;

            deviceWatcher = DeviceInformation.CreateWatcher(DeviceClass.PortableStorageDevice);
            if (deviceWatcher != null)
            {
                deviceWatcher.Added += DeviceAdded;
                deviceWatcher.Removed += DeviceRemoved;
                deviceWatcher.Start();
            }
        }
開發者ID:flecoqui,項目名稱:Windows10,代碼行數:13,代碼來源:MainPage.xaml.cs

示例15: StartWatcher

        void StartWatcher()
        {
            //deviceWatcher = DeviceInformation.CreateWatcher(UsbDevice.GetDeviceSelector(0x04d8, 0xf426));
            deviceWatcher = DeviceInformation.CreateWatcher(UsbDevice.GetDeviceSelector(TreehopperUsb.Settings.Vid, TreehopperUsb.Settings.Pid));
            // Hook up handlers for the watcher events before starting the watcher

            handlerAdded = new TypedEventHandler<DeviceWatcher, DeviceInformation>(async (watcher, deviceInfo) =>
            {
                Debug.WriteLine("Device added: " + deviceInfo.Name);

                UsbConnection newConnection = new UsbConnection(deviceInfo);

                TreehopperUsb newBoard = new TreehopperUsb(newConnection);
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    connectedDevices.Add(newBoard);
                });
                try
                {
                    if (boardAddedSignal.CurrentCount == 0)
                        boardAddedSignal.Release();
                }
                catch { }
            });
            deviceWatcher.Added += handlerAdded;

            handlerUpdated = new TypedEventHandler<DeviceWatcher, DeviceInformationUpdate>((watcher, deviceInfoUpdate) =>
            {
                Debug.WriteLine("Device updated");
            });
            deviceWatcher.Updated += handlerUpdated;

            handlerRemoved = new TypedEventHandler<DeviceWatcher, DeviceInformationUpdate>(async (watcher, deviceInfoUpdate) =>
            {
                Debug.WriteLine("Device removed");
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    connectedDevices.Where(board => ((UsbConnection)(board.Connection)).DevicePath == deviceInfoUpdate.Id).ToList().All(i =>
                    {
                        i.Disconnect();
                        connectedDevices.Remove(i);
                        return true;
                    }
                    );
                });
            });
            deviceWatcher.Removed += handlerRemoved;

            handlerEnumCompleted = new TypedEventHandler<DeviceWatcher, Object>((watcher, obj) =>
            {
                Debug.WriteLine("Enum completed");
            });
            deviceWatcher.EnumerationCompleted += handlerEnumCompleted;

            handlerStopped = new TypedEventHandler<DeviceWatcher, Object>((watcher, obj) =>
            {
                Debug.WriteLine("Device or something stopped");
            });
            deviceWatcher.Stopped += handlerStopped;

            Debug.WriteLine("Starting the wutchah");
            deviceWatcher.Start();
        }
開發者ID:treehopper-electronics,項目名稱:treehopper-sdk,代碼行數:63,代碼來源:ConnectionService.cs


注:本文中的Windows.Devices.Enumeration.DeviceWatcher.Start方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。