svnno****@sourc*****
svnno****@sourc*****
2010年 11月 24日 (水) 02:22:53 JST
Revision: 1101 http://sourceforge.jp/projects/tween/svn/view?view=rev&revision=1101 Author: syo68k Date: 2010-11-24 02:22:53 +0900 (Wed, 24 Nov 2010) Log Message: ----------- タイムアウトの際に10秒待って再接続するようにした Modified Paths: -------------- branches/UserStream/Tween/Twitter.vb -------------- next part -------------- Modified: branches/UserStream/Tween/Twitter.vb =================================================================== --- branches/UserStream/Tween/Twitter.vb 2010-11-23 16:38:33 UTC (rev 1100) +++ branches/UserStream/Tween/Twitter.vb 2010-11-23 17:22:53 UTC (rev 1101) @@ -2767,7 +2767,6 @@ Public Sub StopUserStream() _streamActive = False - RaiseEvent UserStreamStopped() End Sub Public Sub PauseUserStream() @@ -2783,31 +2782,39 @@ Private Sub UserStreamLoop() Dim st As Stream = Nothing Dim sr As StreamReader = Nothing - Try - twCon.UserStream(st) - sr = New StreamReader(st) - Do While _streamActive - Dim line As String = sr.ReadLine() - If _streamBypass OrElse String.IsNullOrEmpty(line) Then Continue Do - Dim s As String = "[" - s += line - s += "]" - Using stream As New MemoryStream() - Dim buf As Byte() = Encoding.Unicode.GetBytes(s) - stream.Write(buf, 0, buf.Length) - stream.Seek(offset:=0, loc:=SeekOrigin.Begin) - CreatePostsFromJson(stream, WORKERTYPE.Timeline, Nothing, False, Nothing, Nothing) - End Using - 'CreatePostsFromJson(s, WORKERTYPE.Timeline, Nothing, False, Nothing, Nothing) - RaiseEvent NewPostFromStream() - Loop - Catch ex As Exception - ExceptionOut(ex) - Finally - _streamActive = False - If sr IsNot Nothing Then sr.BaseStream.Close() - RaiseEvent UserStreamStopped() - End Try + Do + Try + twCon.UserStream(st) + sr = New StreamReader(st) + Do While _streamActive + Dim line As String = sr.ReadLine() + If _streamBypass OrElse String.IsNullOrEmpty(line) Then Continue Do + Dim s As String = "[" + s += line + s += "]" + Using stream As New MemoryStream() + Dim buf As Byte() = Encoding.Unicode.GetBytes(s) + stream.Write(buf, 0, buf.Length) + stream.Seek(offset:=0, loc:=SeekOrigin.Begin) + CreatePostsFromJson(stream, WORKERTYPE.Timeline, Nothing, False, Nothing, Nothing) + End Using + 'CreatePostsFromJson(s, WORKERTYPE.Timeline, Nothing, False, Nothing, Nothing) + RaiseEvent NewPostFromStream() + Loop + Catch ex As WebException + If ex.Status = WebExceptionStatus.Timeout Then + Thread.Sleep(10 * 1000) ' 10秒後に接続再試行 + Else + ExceptionOut(ex) + End If + Catch ex As Exception + ExceptionOut(ex) + Finally + _streamActive = False + If sr IsNot Nothing Then sr.BaseStream.Close() + RaiseEvent UserStreamStopped() + End Try + Loop Until _streamActive = False End Sub Public Event NewPostFromStream()