Exemple #1
0
 public void Dispose()
 {
     _UsbDeviceConnection?.Dispose();
     _UsbDevice?.Dispose();
     _ReadEndpoint?.Dispose();
     _WriteEndpoint?.Dispose();
 }
        /// <summary>
        /// This method demonstrates how to close the device properly using the WinRT Usb API.
        ///
        /// When the UsbDevice is closing, it will cancel all IO operations that are still pending (not complete).
        /// The close will not wait for any IO completion callbacks to be called, so the close call may complete before any of
        /// the IO completion callbacks are called.
        /// The pending IO operations will still call their respective completion callbacks with either a task
        /// cancelled error or the operation completed.
        /// </summary>
        private async void CloseCurrentlyConnectedDevice()
        {
            if (device != null)
            {
                // Notify callback that we're about to close the device
                if (deviceCloseCallback != null)
                {
                    deviceCloseCallback(this, deviceInformation);
                }

                // This closes the handle to the device
                device.Dispose();

                device = null;

                // Save the deviceInformation.Id in case deviceInformation is set to null when closing the
                // device
                String deviceId = deviceInformation.Id;

                await rootPage.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    new DispatchedHandler(() =>
                {
                    MainPage.Current.NotifyUser(deviceId + " is closed", NotifyType.StatusMessage);
                }));
            }
        }
Exemple #3
0
 void Dispose(bool disposing)
 {
     if (disposing)
     {
         device?.Dispose();
     }
 }
Exemple #4
0
 public void Dispose()
 {
     if (NativeDevice != null)
     {
         NativeDevice.Dispose();
         NativeDevice = null;
     }
     if (Connection != null)
     {
         Connection.Dispose();
         Connection = null;
     }
     if (Endpoint != null)
     {
         Endpoint.Dispose();
         Endpoint = null;
     }
     if (EndpointWrite != null)
     {
         EndpointWrite.Dispose();
         EndpointWrite = null;
     }
     if (Manager != null)
     {
         Manager.Dispose();
         Manager = null;
     }
 }
 public void CloseCameraHandle()
 {
     if (_targetDevice != null)
     {
         _targetDevice.Dispose();
         _targetDevice = null;
     }
 }
Exemple #6
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            backgroundTaskInstance = taskInstance;

            // Trigger details contain device id and arguments that are provided by the caller in the main app
            // The taskInstance can always be casted to DeviceUseDetails if this background task was started using a DeviceUseTrigger
            deviceSyncDetails = (DeviceUseDetails)taskInstance.TriggerDetails;

            deferral = taskInstance.GetDeferral();

            try
            {
                backgroundTaskInstance.Progress = 0;

                cancellationTokenSource = new CancellationTokenSource();

                taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);

                // For simplicity, no error checking will be done after opening the device. Ideally, one should always
                // check if the device was successfully opened and respond accordingly. For an example on how to do this,
                // please see Scenario 1 of this sample.
                //
                // The user may also block the device via the settings charm while we are syncing (in background task). In order to deal with
                // the user changing permissions, we have to listen for DeviceAccessInformation->AccessChanged events. See EventHandlerForDevice
                // for how to handle DeviceAccessInformation.AccessChanged event.
                OpenDevice();

                // The sample only demonstrates a bulk write for simplicity.
                // IO operations can be done after opening the device.
                // For more information on BackgroundTasks, please see the BackgroundTask sample on MSDN.
                UInt32 bytesWritten = await Task.Run(() =>
                {
                    return(WriteToDeviceAsync());
                },
                                                     cancellationTokenSource.Token);

                ApplicationData.Current.LocalSettings.Values[LocalSettingKeys.SyncBackgroundTaskResult] = bytesWritten;
                ApplicationData.Current.LocalSettings.Values[LocalSettingKeys.SyncBackgroundTaskStatus] = BackgroundTaskInformation.TaskCompleted;
            }
            catch (OperationCanceledException /*ex*/)
            {
                ApplicationData.Current.LocalSettings.Values[LocalSettingKeys.SyncBackgroundTaskResult] = 0;
                ApplicationData.Current.LocalSettings.Values[LocalSettingKeys.SyncBackgroundTaskStatus] = BackgroundTaskInformation.TaskCanceled;
            }
            finally
            {
                // Close the device because we are finished syncing and so that the app may reopen the device
                device.Dispose();

                device = null;
            }

            // Complete the background task (this raises the OnCompleted event on the corresponding BackgroundTaskRegistration)
            deferral.Complete();
        }
 public void Close()
 {
     if (!IsOpen)
     {
         return;
     }
     cts.Cancel();
     usbDevice.Dispose();
     usbDevice = null;
     Debug.WriteLine("Connection closed");
     IsOpen = false;
 }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposeValue)
            {
                if (disposing)
                {
                    this.disposing = true;
                    _dispatcher.Invoke(() =>
                    {
                        _usbDevice.Dispose();
                        _context.Dispose();
                    });
                }

                disposeValue = true;
            }
        }
Exemple #9
0
        public static void Close()
        {
            if (usbDevice == null)
            {
                return;
            }

            RefreshThreadWanted = false;
            while (RefreshThreadRunning)
            {
                Thread.Sleep(40);
            }

            Thread.Sleep(40);
            WriteText("Goodbye");
            RefreshDisplayAsync().Wait();
            Thread.Sleep(200);

            usbDevice.Close();
            usbDevice.Dispose();
            usbDevice = null;
        }
Exemple #10
0
 public void Dispose()
 {
     UsbDevice.Dispose();
 }
 private void OnAppExiting(object sender, SuspendingEventArgs e)
 {
     _targetDevice?.Dispose();
 }
Exemple #12
0
 /// <summary>
 /// Closes the device and sets the device member variable to null
 /// </summary>
 private void CloseDevice()
 {
     device.Dispose();
     device = null;
 }
 public void Dispose()
 {
     _UsbDeviceConnection?.Dispose();
     _UsbDevice?.Dispose();
 }
Exemple #14
0
 public void Dispose()
 {
     device?.Dispose();
 }