I need my code to respond to the event when my system finds new hardware like USB. How do I go about doing this in C#?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t think there are any .Net classes that can help you do this. So you must fall back on calling the Windows API directly.
When a device changes, Windows sends the WM_DEVICECHANGE message. Write your code to respond to this message.
See this MSDN page about WM_DEVICECHANGE. Also, for details on how to write code to respond to it, see this pdf.
To know about calling Windows API from a C# program, see this article.