Getting more info from exception

  • Thread starter Thread starter Claire
  • Start date Start date
C

Claire

Regarding IOException
I'm catching this error while querying for available serial ports using a
third party component.
I attempt to open then close the comport and if this error type is thrown
then I don't list the port in a combo box.
But I would like to discern between a comport not being available and one
that is available but in use, easy with getlasterror.
Is it possible to do this?
 
Claire,

I think that the way that you are going about it isn't the best. If you
can, I would use the classes in the System.Management namespace to create a
WMI query for all instances of Win32_SerialPort. This would probably be
faster than looping through and catching exceptions (which is expensive).

An added benefit is that if you query for instances of Win32_SerialPort,
then you can get all the other information you need about it (if it is
available or not).

Hope this helps.
 
thanks Nicholas.
I think the knowledge of how to go about this is way beyond my few days xp
of C#.
Ive added the system.management reference to my project, took a look at the
help file and my heart dropped.
Are there some example code snippets somewhere that would give me a hint on
where to start (im working from home today so no reference books. Not even
sure if they would contain this sort of thing)

Nicholas Paldino said:
Claire,

I think that the way that you are going about it isn't the best. If you
can, I would use the classes in the System.Management namespace to create a
WMI query for all instances of Win32_SerialPort. This would probably be
faster than looping through and catching exceptions (which is expensive).

An added benefit is that if you query for instances of Win32_SerialPort,
then you can get all the other information you need about it (if it is
available or not).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Claire said:
Regarding IOException
I'm catching this error while querying for available serial ports using a
third party component.
I attempt to open then close the comport and if this error type is thrown
then I don't list the port in a combo box.
But I would like to discern between a comport not being available and one
that is available but in use, easy with getlasterror.
Is it possible to do this?
 
I've found some code within the SelectQuery class.
Many thanks for your pointers, great :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top