Click here to Skip to main content
15,917,862 members
Home / Discussions / C#
   

C#

 
AnswerRe: sourcecode test client by c# - TROLL Pin
Mycroft Holmes25-Aug-10 19:43
professionalMycroft Holmes25-Aug-10 19:43 
AnswerRe: sourcecode test client by c# Pin
Bigdeak25-Aug-10 20:27
Bigdeak25-Aug-10 20:27 
QuestionToolStripMenuItem.Visible always returns false? Pin
AussieLew25-Aug-10 15:58
AussieLew25-Aug-10 15:58 
AnswerRe: ToolStripMenuItem.Visible always returns false? Pin
johannesnestler25-Aug-10 22:19
johannesnestler25-Aug-10 22:19 
GeneralRe: ToolStripMenuItem.Visible always returns false? Pin
AussieLew26-Aug-10 15:23
AussieLew26-Aug-10 15:23 
GeneralRe: ToolStripMenuItem.Visible always returns false? [modified] Pin
AussieLew26-Aug-10 15:46
AussieLew26-Aug-10 15:46 
AnswerRe: ToolStripMenuItem.Visible always returns false? Pin
Gonzalo Cao26-Aug-10 0:38
Gonzalo Cao26-Aug-10 0:38 
QuestionSerialPort has memory leak Pin
fukchai200025-Aug-10 7:26
fukchai200025-Aug-10 7:26 
Hi Guys,

I had windows service that will listen to a COM port and somehow after run for hours, memory leak start happening.

So I created 2 simple programs.

First one, send a data through COM2 (Console):

private static byte[] serialBuffer = new byte[1];
static SerialPort sPort = new SerialPort();
static void Main(string[] args)
{			
	sPort.PortName = "COM2";						
	sPort.Open();

	string data= String.Empty;
	int startNumber = 100000;
	while (startNumber < 1)
	{
		data = DateTime.Now.ToString("dd MM yy hh mm ss");
		data = data + " " + data + " " + data;

		byte[] tmp = HexStringToByteArray(data);
		sPort.Write(tmp, 0, tmp.Length);

		Thread.Sleep(500);
		startNumber--;
	}
}

private static byte[] HexStringToByteArray(string s)
{
	s = s.Replace(" ", "");
	byte[] buffer = new byte[s.Length / 2];
	for (int i = 0; i < s.Length; i += 2)
		buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16);
	return buffer;
}



Next one is the receiving part and write back to COM1 port (Windows form):

SerialPort _serialPort = new SerialPort();
public Form1()
{
	InitializeComponent();
	_serialPort.PortName = "COM1";
	_serialPort.Open();
	_serialPort.DataReceived += new SerialDataReceivedEventHandler(tccuSerialPort_DataReceived);
}

byte[] serialBuffer = new byte[1];
private void tccuSerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
	int bytesToRead = _serialPort.BytesToRead;
	if (bytesToRead > 256)
		bytesToRead = 256;

	if (bytesToRead > 0)
	{
		serialBuffer = new byte[bytesToRead];
		_serialPort.Read(serialBuffer, 0, bytesToRead);		
		listBox1.Items.Add("RECEIVED");
		_serialPort.Write(new byte[1] { 0x01 }, 0, 1);
	}
	serialBuffer = null;
}


When I run the programs, the 2nd program's memory start to leak. (receiving program)
I have no idea if anybody encounter this problem before? can provide some advice?

Thanks in advance.
AnswerRe: SerialPort has memory leak Pin
QuiJohn25-Aug-10 8:15
QuiJohn25-Aug-10 8:15 
AnswerRe: I never encountered a memory leak while using SerialPort Pin
Luc Pattyn25-Aug-10 8:50
sitebuilderLuc Pattyn25-Aug-10 8:50 
AnswerRe: SerialPort has memory leak Pin
Dan Mos25-Aug-10 10:49
Dan Mos25-Aug-10 10:49 
QuestionConverting Array list to VBA.Collection in c# Pin
kjsl2k925-Aug-10 3:12
kjsl2k925-Aug-10 3:12 
AnswerRe: Converting Array list to VBA.Collection in c# Pin
dan!sh 25-Aug-10 5:25
professional dan!sh 25-Aug-10 5:25 
AnswerRe: Converting Array list to VBA.Collection in c# Pin
Eddy Vluggen25-Aug-10 7:28
professionalEddy Vluggen25-Aug-10 7:28 
QuestionCtrl + Enter key functionality in webbrowser application (win app) Pin
Krishna Varadharajan25-Aug-10 2:39
Krishna Varadharajan25-Aug-10 2:39 
AnswerRe: Ctrl + Enter key functionality in webbrowser application (win app) Pin
dan!sh 25-Aug-10 2:49
professional dan!sh 25-Aug-10 2:49 
GeneralRe: Ctrl + Enter key functionality in webbrowser application (win app) Pin
Luc Pattyn25-Aug-10 3:40
sitebuilderLuc Pattyn25-Aug-10 3:40 
GeneralRe: Ctrl + Enter key functionality in webbrowser application (win app) Pin
Bernhard Hiller25-Aug-10 3:46
Bernhard Hiller25-Aug-10 3:46 
QuestionProject Help Pin
Mamatha302425-Aug-10 2:18
Mamatha302425-Aug-10 2:18 
AnswerRe: Project Help Pin
Richard MacCutchan25-Aug-10 2:47
mveRichard MacCutchan25-Aug-10 2:47 
GeneralRe: Project Help Pin
PIEBALDconsult25-Aug-10 15:21
mvePIEBALDconsult25-Aug-10 15:21 
GeneralRe: Project Help Pin
Richard MacCutchan25-Aug-10 22:47
mveRichard MacCutchan25-Aug-10 22:47 
AnswerRe: Project Help Pin
Abhinav S25-Aug-10 5:57
Abhinav S25-Aug-10 5:57 
AnswerRe: Project Help Pin
Pete O'Hanlon25-Aug-10 13:07
mvePete O'Hanlon25-Aug-10 13:07 
AnswerRe: Project Help Pin
Luc Pattyn25-Aug-10 13:39
sitebuilderLuc Pattyn25-Aug-10 13:39 

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.