✅ Can you lock or freeze a thread while using another form in a new thread??
Part of my application requires i detect a USB device, and grab the DeviceID, I've got this and works fine, how ever im trying to get it to open a new form when it detects that the device is connected. again i got this working.
the issue i got is i want it open a form and pass in a serial number from the USB. again i got this working but had to open the form by spawning a new thread. however dispite the form being open as Showdialog(), i can still access the main form. im assuming this is because they are on 2 separate threads. am i able to lock the previous thread while i have the new form open ??? and when it closes unlock it?
this is my code for opening the form currently
19 Replies
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
ok ty, il go have a read up on these
new Thread(() => new USBPopup(serialNumber).ShowDialog()).Start();aren't you meant to use dispatcher to run/queue thinhgs on the ui thread? https://learn.microsoft.com/en-us/dotnet/api/system.windows.threading.dispatcher.invoke?view=windowsdesktop-7.0
Dispatcher.Invoke Method (System.Windows.Threading)
Executes the specified delegate synchronously on the thread the Dispatcher is associated with.
no idea as I'm a novice, and just learning as i go, I've worked out a way to do this now though with out too much effort
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
im using winforms
i am having another issue if you can help thow
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
ive got a usb device but it reports 2 PNPdevice IDs, , i got my code opening and closing a form based on detection and removal
but on removal the usb with 2 ids loads a 2nd form
been playing for hours no trying to sort it lol
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
yea this is a unique device
has 2 device IDs
il get a video asec
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
wrong veideo
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
so one usb stick has 2 PNPDeviceID's
`
Unknown User•17mo ago
Message Not Public
Sign In & Join Server To View
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.what I'm seeing is correct, as i suspect this this is 2 usbs rolled into one. how ever my code should break out of the loop when it finds the first PNPDeviceID,
but it doesn't, i get one prompt which im expecting and is successful, then when i remove the usb a 2nd prompt pop s up for the 2nd pnp device
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.