Ejemplo n.º 1
0
        //========================================================================================
        // Methods
        //========================================================================================

        /// <summary>
        /// When a USB device comes online or goes offline, this handler manages the
        /// disk collection accordingly.
        /// </summary>
        /// <param name="e"></param>

        private void DoStateChanged(UsbStateChangedEventArgs e)
        {
            if (e.State == UsbStateChange.Added)
            {
                if (!disks.Contains(e.Disk.Name))
                {
                    disks.Add(e.Disk);
                }
            }
            else if (e.State == UsbStateChange.Removed)
            {
                if (disks.Contains(e.Disk.Name))
                {
                    disks.Remove(e.Disk.Name);
                }
            }

            ConveyDevices();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Internally handle state changes and notify listeners.
        /// </summary>
        /// <param name="e"></param>

        private void DoStateChanged(UsbStateChangedEventArgs e)
        {
            if (handler != null)
            {
                UsbDisk disk = e.Disk;

                // we can only interrogate drives that are added...
                // cannot see something that is no longer there!

                if ((e.State == UsbStateChange.Added) && (e.Disk.Name[0] != '?'))
                {
                    // the following Begin/End invokes looks strange but are required
                    // to resolve a "DisconnectedContext was detected" exception which
                    // occurs when the current thread terminates before the WMI queries
                    // can complete.  I'm not exactly sure why that would happen...

                    GetDiskInformationDelegate gdi = new GetDiskInformationDelegate(GetDiskInformation);
                    IAsyncResult result            = gdi.BeginInvoke(e.Disk, null, null);
                    gdi.EndInvoke(result);
                }

                handler(e);
            }
        }
Ejemplo n.º 3
0
        void man_StateChanged(UsbStateChangedEventArgs e)
        {
            if(e.Disk != null)
                Log.Info("USB State Changed: " + e.State + ", " + e.Disk.Name);
            else
                Log.Info("USB State Changed: " + e.State);

            switch (e.State)
            {
                case UsbStateChange.Added:
                    Drives.Add(e.Disk);
                    break;
                case UsbStateChange.Removing:
                case UsbStateChange.Removed:
                    Drives.Remove(e.Disk.Name);
                    break;
            }

            if (this.Path == null) UpdateCurrentPath();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Internally handle state changes and notify listeners.
        /// </summary>
        /// <param name="e"></param>
        private void DoStateChanged(UsbStateChangedEventArgs e)
        {
            if (handler != null)
            {
                UsbDisk disk = e.Disk;

                // we can only interrogate drives that are added...
                // cannot see something that is no longer there!

                if ((e.State == UsbStateChange.Added) && (e.Disk.Name[0] != '?'))
                {
                    // the following Begin/End invokes looks strange but are required
                    // to resolve a "DisconnectedContext was detected" exception which
                    // occurs when the current thread terminates before the WMI queries
                    // can complete.  I'm not exactly sure why that would happen...

                    GetDiskInformationDelegate gdi = new GetDiskInformationDelegate(GetDiskInformation);
                    IAsyncResult result = gdi.BeginInvoke(e.Disk, null, null);
                    gdi.EndInvoke(result);
                }

                handler(e);
            }
        }
Ejemplo n.º 5
0
        private void DoStateChanged(UsbStateChangedEventArgs e)
        {
            if(e.State.ToString()=="Inserted")
               {
               Commit_Usb_Data(e.Disk.ToString()+" "+"Inserted");
               MessageBox.Show(e.State + " " + e.Disk.ToString());
               Last_Usb = e.Disk.ToString();

               }
               else
               {

               MessageBox.Show(e.State + " " + Last_Usb);
               Last_Usb = " ";
               }
            //MessageBox.Show(e.State + " " + e.Disk.ToString());
        }
Ejemplo n.º 6
0
 private void manager_StateChanged(UsbStateChangedEventArgs e)
 {
     Console.WriteLine(e.State.ToString() + " - " + e.Disk.ToString());
     Debug.WriteLine(e.State.ToString() + " - " + e.Disk.ToString());
 }
Ejemplo n.º 7
0
        //========================================================================================
        // Methods
        //========================================================================================
        /// <summary>
        /// When a USB device comes online or goes offline, this handler manages the
        /// disk collection accordingly.
        /// </summary>
        /// <param name="e"></param>
        private void DoStateChanged(UsbStateChangedEventArgs e)
        {
            if (e.State == UsbStateChange.Added)
            {
                if (!disks.Contains(e.Disk.Name))
                {
                    disks.Add(e.Disk);
                }
            }
            else if (e.State == UsbStateChange.Removed)
            {
                if (disks.Contains(e.Disk.Name))
                {
                    disks.Remove(e.Disk.Name);
                }
            }

            ConveyDevices();
        }