Index: trunk/Include/Classes/System/Console.ab
===================================================================
--- trunk/Include/Classes/System/Console.ab	(revision 434)
+++ trunk/Include/Classes/System/Console.ab	(revision 435)
@@ -36,8 +36,43 @@
 	*/
 	Static Function ReadLine() As String
-		ReadLine = in.ReadLine()
+		Dim lock = enter()
+		Try
+			ReadLine = in.ReadLine()
+		Finally
+			lock.Leave()
+		End Try
+	End Function
+
+	/*
+	@brief 標準入力から1行読み込む
+	@date 2008/02/26
+	@auther Egtra
+	*/
+	Static Function Read() As Long
+		Dim lock = enter()
+		Try
+			Read = in.Read()
+		Finally
+			lock.Leave()
+		End Try
 	End Function
 Private
+	Function enter() As ActiveBasic.Windows.CriticalSectionLock
+		Imports ActiveBasic.Windows
+		If ActiveBasic.IsNothing(cs) Then
+			Dim lock = New CriticalSectionLock(_System_CriticalSection)
+			Try
+				If ActiveBasic.IsNothing(cs) Then
+					cs = New CriticalSection
+				End If
+			Finally
+				lock.Dispose()
+			End Try
+		End If
+		enter = cs.Enter
+	End Function
+
 	Static in = Nothing As IO.TextReader
+	Static cs = Nothing As ActiveBasic.Windows.CriticalSection
 End Class
 
Index: trunk/Include/Classes/System/Exception.ab
===================================================================
--- trunk/Include/Classes/System/Exception.ab	(revision 434)
+++ trunk/Include/Classes/System/Exception.ab	(revision 435)
@@ -152,5 +152,5 @@
 		Return src
 	End Function
-Protected
+
 	/*!
 	@brief	HRESULT値の設定
Index: trunk/Include/Classes/System/IO/Exception.ab
===================================================================
--- trunk/Include/Classes/System/IO/Exception.ab	(revision 434)
+++ trunk/Include/Classes/System/IO/Exception.ab	(revision 435)
@@ -64,5 +64,5 @@
 	*/
 	Sub ThrowWinIOException(msg As String, error As DWord)
-'		Throw IOException(msg, HRESULT_FROM_WIN32(error))
+		Throw New IOException(msg, HRESULT_FROM_WIN32(error))
 	End Sub
 
@@ -74,5 +74,5 @@
 	*/
 	Sub ThrowWinLastErrorIOException(msg As String)
-'		Throw IOException(msg, HRESULT_FROM_WIN32(GetLastError()))
+		Throw New IOException(msg, HRESULT_FROM_WIN32(GetLastError()))
 	End Sub
 End Namespace
Index: trunk/Include/Classes/System/IO/File.ab
===================================================================
--- trunk/Include/Classes/System/IO/File.ab	(revision 434)
+++ trunk/Include/Classes/System/IO/File.ab	(revision 435)
@@ -27,10 +27,10 @@
 
 Enum FileMode
-	Append = OPEN_ALWAYS
-	Create = CREATE_ALWAYS
-	CreateNew = CREATE_NEW
-	Open = OPEN_EXISTING
-	OpenOrCreate = OPEN_ALWAYS
-	Truncate = TRUNCATE_EXISTING
+	Append = 4 'OPEN_ALWAYS
+	Create = 2 'CREATE_ALWAYS
+	CreateNew = 1 'CREATE_NEW
+	Open = 3 'OPEN_EXISTING
+	OpenOrCreate = 4 'OPEN_ALWAYS
+	Truncate = 5 'TRUNCATE_EXISTING
 End Enum
 
Index: trunk/Include/Classes/System/IO/FileStream.ab
===================================================================
--- trunk/Include/Classes/System/IO/FileStream.ab	(revision 434)
+++ trunk/Include/Classes/System/IO/FileStream.ab	(revision 435)
@@ -34,4 +34,11 @@
 	/* コンストラクタ.NETと同じように実装は難しい、一先ず動くものを実装したが変更が必要だと思う */
 	Sub FileStream(path As String, mode As FileMode, access As FileAccess, share As FileShare, options As FileOptions)
+		If ActiveBasic.IsNothing(path) Then
+			Throw New ArgumentNullException("path")
+		ElseIf path.Length = 0 Then
+			Throw New ArgumentException
+		End If
+
+
 		Dim ac = access As DWord
 		Dim sh = share As DWord
@@ -49,5 +56,5 @@
 		'Throw System.IO.FileNotFoundException 
 			This.handle=0
-			Beep(220,500)
+			Detail.ThrowWinLastErrorIOException("Failed to open/create file.")
 			Exit Sub
 		End If
Index: trunk/Include/Classes/System/IO/StreamReader.ab
===================================================================
--- trunk/Include/Classes/System/IO/StreamReader.ab	(revision 434)
+++ trunk/Include/Classes/System/IO/StreamReader.ab	(revision 435)
@@ -50,5 +50,7 @@
 	Override Function Read() As Long
 		Read = Peek()
-		cur++
+		If Read <> -1 Then
+			cur++
+		End If
 	End Function
 
Index: trunk/Include/Classes/System/Text/StringBuilder.ab
===================================================================
--- trunk/Include/Classes/System/Text/StringBuilder.ab	(revision 434)
+++ trunk/Include/Classes/System/Text/StringBuilder.ab	(revision 435)
@@ -387,9 +387,11 @@
 
 		Dim s = New StringBuilder(capacity, maxCapacity)
-		Dim curPos = 0 As Long
+		Dim curPos = start
+		Dim last = start + count
 		Do
 			Dim nextPos = ActiveBasic.Strings.ChrFind(VarPtr(chars[curPos]) As *StrChar, size As SIZE_T, StrPtr(oldStr), oldStr.Length As SIZE_T) As Long
-			If nextPos = -1 As SIZE_T Then
-				Exit Sub
+			If nextPos = -1 As SIZE_T Or curPos > last Then
+				s.appendCore(chars, curPos, size - curPos)
+				Exit Do
 			End If
 			
