Click here to Skip to main content
15,890,282 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to Generate data on Crystal Report when Datagridview item is selected Pin
Dambod14-Aug-09 8:25
Dambod14-Aug-09 8:25 
GeneralRe: How to Generate data on Crystal Report when Datagridview item is selected Pin
Dave Kreskowiak14-Aug-09 8:35
mveDave Kreskowiak14-Aug-09 8:35 
GeneralRe: How to Generate data on Crystal Report when Datagridview item is selected Pin
Paramu197314-Aug-09 19:46
Paramu197314-Aug-09 19:46 
GeneralRe: How to Generate data on Crystal Report when Datagridview item is selected Pin
Dave Kreskowiak15-Aug-09 2:21
mveDave Kreskowiak15-Aug-09 2:21 
GeneralRe: How to Generate data on Crystal Report when Datagridview item is selected Pin
Paramu197315-Aug-09 6:08
Paramu197315-Aug-09 6:08 
GeneralSolved Pin
Dambod16-Aug-09 3:58
Dambod16-Aug-09 3:58 
QuestionVB.net 2008, TCPClient Streams Pin
DaveAuld14-Aug-09 7:21
professionalDaveAuld14-Aug-09 7:21 
AnswerRe: VB.net 2008, TCPClient Streams Pin
Dave Kreskowiak14-Aug-09 8:07
mveDave Kreskowiak14-Aug-09 8:07 
First thing I see is that you're not passing anything in as the state tracking object in your BeginConnect and BeginRead calls. You're trying to substitute using class-level objects for state tracking and misusing them. I think that is what is causing your problem.

I normal do something like this. Create a custom object that contains the buffer and Stream being read.
Public Class AsyncReadTracker
    Public buffer(20480) As Byte
    Public s As Stream
End Class


I create a method to start the Async Read of the incoming stream, creating a new tracking object and passing the buffer in the object to the BeginRead method, as well as the callback delegate and the tracking object itself. You'll see why in a second...
Private Sub StartAsyncRead(ByRef st As Stream)
    Dim art As New AsyncReadTracker

    art.s = st

    Dim ReadAsyncCallback As New AsyncCallback(AddressOf ReadCallback)
    st.BeginRead(art.buffer, 0, art.buffer.Length, ReadAsyncCallback, art)
End Sub


In the read callback delegate, the IAsyncResult parameter is there for a reason. Use it. The tracking object will pass the buffer that contains the data and the stream that it was read from to the next call of BeginRead. When BeginRead calls the ReadCallback delegate, it'll pass the tracking object to the delegate. The delegate will pass the stream back to the new call to StartAsyncRead so the same stream can continue to be read.
Private Sub ReadCallback(ByVal asyncResult As IAsyncResult)
    Dim art As AsyncReadTracker = DirectCast(asyncResult.AsyncState, AsyncReadTracker)
    Dim bytesRead As Integer = art.s.EndRead(asyncResult)
    Dim enc As Encoding = Encoding.ASCII
    Dim s As String = enc.GetString(art.buffer, 0, bytesRead)
    
    ' Do something with the data you just got...
 
    ' Now start the Async Read process on the stream we've been using, all over again.
    StartAsyncRead(art.s)
End Sub



A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007, 2008
But no longer in 2009...




GeneralRe: VB.net 2008, TCPClient Streams Pin
DaveAuld14-Aug-09 8:30
professionalDaveAuld14-Aug-09 8:30 
QuestionHow can I force a user to enter a string with characters only with no integer from a text box? Pin
waner michaud14-Aug-09 6:45
waner michaud14-Aug-09 6:45 
AnswerRe: How can I force a user to enter a string with characters only with no integer from a text box? Pin
Dave Kreskowiak14-Aug-09 7:42
mveDave Kreskowiak14-Aug-09 7:42 
AnswerRe: How can I force a user to enter a string with characters only with no integer from a text box? Pin
waner michaud14-Aug-09 11:41
waner michaud14-Aug-09 11:41 
GeneralRe: How can I force a user to enter a string with characters only with no integer from a text box? Pin
Luc Pattyn14-Aug-09 12:38
sitebuilderLuc Pattyn14-Aug-09 12:38 
Questionpassing values from a windows form to a crystal report Pin
myinstincts14-Aug-09 0:12
myinstincts14-Aug-09 0:12 
AnswerRe: passing values from a windows form to a crystal report Pin
Johan Hakkesteegt14-Aug-09 0:41
Johan Hakkesteegt14-Aug-09 0:41 
GeneralRe: passing values from a windows form to a crystal report Pin
myinstincts14-Aug-09 1:57
myinstincts14-Aug-09 1:57 
GeneralRe: passing values from a windows form to a crystal report Pin
Johan Hakkesteegt14-Aug-09 2:10
Johan Hakkesteegt14-Aug-09 2:10 
GeneralRe: passing values from a windows form to a crystal report Pin
myinstincts14-Aug-09 2:17
myinstincts14-Aug-09 2:17 
GeneralRe: passing values from a windows form to a crystal report Pin
Johan Hakkesteegt14-Aug-09 2:43
Johan Hakkesteegt14-Aug-09 2:43 
GeneralRe: passing values from a windows form to a crystal report Pin
myinstincts14-Aug-09 2:49
myinstincts14-Aug-09 2:49 
AnswerRe: passing values from a windows form to a crystal report Pin
Anubhava Dimri17-Aug-09 0:07
Anubhava Dimri17-Aug-09 0:07 
QuestionBring to Front and Send to back Pin
Anubhava Dimri13-Aug-09 23:55
Anubhava Dimri13-Aug-09 23:55 
AnswerRe: Bring to Front and Send to back Pin
0x3c014-Aug-09 0:17
0x3c014-Aug-09 0:17 
GeneralRe: Bring to Front and Send to back Pin
Coding C#14-Aug-09 2:50
Coding C#14-Aug-09 2:50 
GeneralRe: Bring to Front and Send to back Pin
Anubhava Dimri16-Aug-09 23:48
Anubhava Dimri16-Aug-09 23:48 

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.