Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. USB device being in use

USB device being in use

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blubbo
    wrote on last edited by
    #1

    I know there is a way to tell if the usb device is in use. When one application fetches one usb device, the other application is unable to get the same device handle because it already "taken" by the 1st application. right now, my two application are able to get the same usb devices. any suggestion on how to prevent the 2nd application from detecting or open the usb device that is already taken by the other application?

    L 1 Reply Last reply
    0
    • B Blubbo

      I know there is a way to tell if the usb device is in use. When one application fetches one usb device, the other application is unable to get the same device handle because it already "taken" by the 1st application. right now, my two application are able to get the same usb devices. any suggestion on how to prevent the 2nd application from detecting or open the usb device that is already taken by the other application?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use a "Mutex". Before "taking" the usb device, each application tries to create a Mutex. If the Mutex is created, the device was free; else the "other" app is using the device (because "it" has already created the Mutex).

      B 1 Reply Last reply
      0
      • L Lost User

        Use a "Mutex". Before "taking" the usb device, each application tries to create a Mutex. If the Mutex is created, the device was free; else the "other" app is using the device (because "it" has already created the Mutex).

        B Offline
        B Offline
        Blubbo
        wrote on last edited by
        #3

        hmm I don't think Mutex would do. Tried to understand Mutex. but what about with this method?

        DeviceHandle = CreateFile(DevicePath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, ref Security, OPEN_EXISTING, 0, 0);

        Tried to understand it a bit too. If I use 0 in place of FILE_SHARE_READ | FILE_SHARE_WRITE, would this be a good idea?

        L 1 Reply Last reply
        0
        • B Blubbo

          hmm I don't think Mutex would do. Tried to understand Mutex. but what about with this method?

          DeviceHandle = CreateFile(DevicePath, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, ref Security, OPEN_EXISTING, 0, 0);

          Tried to understand it a bit too. If I use 0 in place of FILE_SHARE_READ | FILE_SHARE_WRITE, would this be a good idea?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          A Mutex is simply a way to communicate a semaphor between processes. If you're considering CreateFile, then you should go to the Windows API forum.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups