Click here to Skip to main content
15,909,737 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reflection ! Pin
DaveyM6925-Mar-09 11:50
professionalDaveyM6925-Mar-09 11:50 
GeneralRe: Reflection ! Pin
Mohammad Dayyan25-Mar-09 11:53
Mohammad Dayyan25-Mar-09 11:53 
GeneralRe: Reflection ! Pin
DaveyM6925-Mar-09 12:31
professionalDaveyM6925-Mar-09 12:31 
GeneralRe: Reflection ! Pin
Luc Pattyn25-Mar-09 13:31
sitebuilderLuc Pattyn25-Mar-09 13:31 
QuestionDepedencies Pin
CodingYoshi25-Mar-09 11:04
CodingYoshi25-Mar-09 11:04 
AnswerRe: Depedencies Pin
Colin Angus Mackay25-Mar-09 14:43
Colin Angus Mackay25-Mar-09 14:43 
QuestionRemoving a duplicate row C# and WMI Pin
Buck_Murdock25-Mar-09 10:57
Buck_Murdock25-Mar-09 10:57 
QuestionAnybody here handle what happens when you unplug a USB based Serial Port? Pin
Wes Jones25-Mar-09 10:26
Wes Jones25-Mar-09 10:26 
Hi all,

I've been searching high,low, and in between for a solution to my current problem & thought I'd post here to see if anyone here has tackled this one before.

I'm using VS2008, C#, & .Net3.5 SP1.

I have a USB based COM port attached to a GPS device, and I'm testing what happens when you unplug the USB cable while the SerialPort connection is open. The results are an unhandled exception & a program crash that occurs when the SerialPort.BaseStream is garbage collected, according to the callstack when the exception occurs..

The problem is discussed a bit @ this link[^], which includes this sample to reproduce:

using System;
using System.IO.Ports;

namespace SerialPortUsbCrash {
class Program {
    static void Main(string[] args) {
     SerialPort serialPort = null;
     serialPort = new SerialPort("COM12", 19200, Parity.None, 8, 
StopBits.One);
     serialPort.Open();
     Console.Write("Pull out the USB cable, and push return");
     Console.ReadLine();
     try {
        serialPort.Close();
     } catch (Exception ex) {
        Console.WriteLine("Got exception closing SerialPort: " + ex);
     }
     Console.WriteLine("- THE END -");
     Console.ReadLine();
    }
}


I've tried a number of suggestions based on google searches, including app.config change, closing/disposing SerialPort on WM_DEVICECHANGE, GC.SuppressFinalization(serialPort.BaseStream) on device removal & others, but they don't resolve the issue.

Anybody here figure this one out?

Thanks.
AnswerRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Henry Minute25-Mar-09 10:52
Henry Minute25-Mar-09 10:52 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Wes Jones25-Mar-09 11:04
Wes Jones25-Mar-09 11:04 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Henry Minute25-Mar-09 11:15
Henry Minute25-Mar-09 11:15 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
DaveyM6925-Mar-09 11:19
professionalDaveyM6925-Mar-09 11:19 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Luc Pattyn25-Mar-09 13:36
sitebuilderLuc Pattyn25-Mar-09 13:36 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Colin Angus Mackay25-Mar-09 14:48
Colin Angus Mackay25-Mar-09 14:48 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Wes Jones25-Mar-09 15:34
Wes Jones25-Mar-09 15:34 
AnswerRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Henry Minute25-Mar-09 11:41
Henry Minute25-Mar-09 11:41 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
DaveyM6925-Mar-09 11:43
professionalDaveyM6925-Mar-09 11:43 
QuestionStreamWriter help... Pin
VoodooInfinity25-Mar-09 10:07
VoodooInfinity25-Mar-09 10:07 
AnswerRe: StreamWriter help... Pin
BOMBONEW25-Mar-09 10:14
BOMBONEW25-Mar-09 10:14 
GeneralRe: StreamWriter help... [modified] Pin
VoodooInfinity25-Mar-09 10:23
VoodooInfinity25-Mar-09 10:23 
AnswerRe: StreamWriter help... Pin
J$25-Mar-09 10:34
J$25-Mar-09 10:34 
AnswerRe: StreamWriter help... Pin
Ian Shlasko25-Mar-09 10:34
Ian Shlasko25-Mar-09 10:34 
QuestionC# and Data Acquisition Application Pin
stancrm25-Mar-09 10:06
stancrm25-Mar-09 10:06 
JokeRe: C# and Data Acquisition Application Pin
Eddy Vluggen25-Mar-09 10:31
professionalEddy Vluggen25-Mar-09 10:31 
AnswerRe: C# and Data Acquisition Application Pin
DaveyM6925-Mar-09 11:26
professionalDaveyM6925-Mar-09 11:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.