Click here to Skip to main content
15,920,632 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionAccess denied. Pin
Aaron12828-Aug-06 9:54
Aaron12828-Aug-06 9:54 
AnswerRe: Access denied. Pin
kumarprabhakar7429-Aug-06 0:51
kumarprabhakar7429-Aug-06 0:51 
GeneralRe: Access denied. Pin
Aaron1281-Sep-06 2:43
Aaron1281-Sep-06 2:43 
Questionhow to create database during setup installation Pin
md_refay28-Aug-06 7:45
md_refay28-Aug-06 7:45 
AnswerRe: how to create database during setup installation Pin
Polymorpher28-Aug-06 17:09
Polymorpher28-Aug-06 17:09 
GeneralRe: how to create database during setup installation Pin
Navi1528-Aug-06 19:01
Navi1528-Aug-06 19:01 
Questionvb.net templete... Pin
CCG328-Aug-06 3:57
CCG328-Aug-06 3:57 
QuestionAsync thread safe operation help please [modified] Pin
g12net28-Aug-06 3:22
g12net28-Aug-06 3:22 
Hi all

This is my first post so please be gentle!!

Ok im not new entirely to VB.net but I am totally new to threading/async calls/cross thread interaction.

The sample code below is an async operation to catch received socket traffic.
The async method works just fine in capturing what i need, now i need to raise an event from my class to the form it was instantiated on, but doing so in a thread safe manner. To do this I have been using a sync object of type "System.ComponentModel.ISynchronizeInvoke". I pass my main form to this object as the synchronising object. as below (this is the new method of my class)

<br />
Public Sub New(ByVal BufferSize As Int32, ByVal SyncObject As     System.ComponentModel.ISynchronizeInvoke)<br />
    _SyncObject = SyncObject<br />
    _Connected = False<br />
    _BufferSize = BufferSize<br />
End Sub<br />


Now this sync object i use handles all my thread safe calls without any issue except for my receive method as follows:

Private Sub BeginReceive(ByVal ar As IAsyncResult)<br />
            Try<br />
                Dim _Bytes As Byte() = CType(ar.AsyncState, Byte())<br />
                Dim _numBytes As Int32 = _Socket.EndReceive(ar)<br />
<br />
                If _numBytes = 0 Then<br />
                    Dim c As New dlgNoParams(AddressOf Disconnect)<br />
                    _SyncObject.Invoke(c, Nothing)<br />
                Else<br />
                    Dim _Data As String = _Ascii.GetString(_Bytes)<br />
                    Dim args(0) As Object<br />
                    args(0) = _Data<br />
                    Dim d As New dlgReceiveData(AddressOf ReceiveData)<br />
                    _SyncObject.Invoke(d, args)<br />
                    Dim e As New dlgNoParams(AddressOf StartReceive)<br />
                    _SyncObject.Invoke(e, Nothing)<br />
                End If<br />
            Catch ex As Exception<br />
<br />
                Dim myType As Type = ex.GetType<br />
                Console.WriteLine(myType.ToString)<br />
                If Not myType.FullName = "System.Net.Sockets.SocketException" Then<br />
                    Dim f As New dlgErrorEvent(AddressOf ErrorEvent)<br />
                    Dim args(0) As Object<br />
                    args(0) = ex<br />
                    _SyncObject.Invoke(f, args)<br />
                Else<br />
                    '_QueueThread.Abort()<br />
                    _Socket = Nothing<br />
                End If<br />
            End Try<br />
        End Sub


I have several other methods that are executed on the forms main thread using the same methods as obove but just references different delegates, but the basics behind them all are very similar.

Every time i receive data through the socket i get a "NullReferenceException was Unhandled" with a message of{"Object reference not set to an instance of an object."}

Can anyone point me in the right direction please? or offer me an alternative to a thread safe method of raising an event within my class that runs from this async thread please?

Many thanks in advance and thanks for looking Smile | :)

Highlander

It seems this only errors out when passing the args object as a 1-dimensional array which holds a string. If i pass the word 'Nothing' instead of the args object i dont get the error. But i need to pass args as the method processes the data and raises the appropriate event. Any ideas? I have Bold/Underlined the offending line where i get the error. Thanks again
-- modified at 10:58 Monday 28th August, 2006
QuestionCreate A CSV File in Window Appliaction Pin
HatakeKaKaShi28-Aug-06 1:10
HatakeKaKaShi28-Aug-06 1:10 
AnswerRe: Create A CSV File in Window Appliaction Pin
g12net28-Aug-06 3:29
g12net28-Aug-06 3:29 
QuestionHow to see data properly in text box Pin
Nabeel_nab28-Aug-06 0:06
Nabeel_nab28-Aug-06 0:06 
AnswerRe: How to see data properly in text box Pin
Navi1528-Aug-06 1:46
Navi1528-Aug-06 1:46 
QuestionComboBox Column in DataGridView Pin
Maira K27-Aug-06 20:28
Maira K27-Aug-06 20:28 
QuestionCould not release a dbf file Pin
HieuGSE27-Aug-06 16:17
HieuGSE27-Aug-06 16:17 
AnswerRe: Could not release a dbf file Pin
g12net28-Aug-06 3:33
g12net28-Aug-06 3:33 
GeneralRe: Could not release a dbf file Pin
HieuGSE29-Aug-06 19:16
HieuGSE29-Aug-06 19:16 
Questiondelete multiple record on access- vb6 [modified] Pin
campbells27-Aug-06 15:20
campbells27-Aug-06 15:20 
AnswerRe: delete multiple record on access- vb6 Pin
Ray Cassick27-Aug-06 16:30
Ray Cassick27-Aug-06 16:30 
GeneralRe: delete multiple record on access- vb6 Pin
Ray Cassick27-Aug-06 17:38
Ray Cassick27-Aug-06 17:38 
GeneralRe: delete multiple record on access- vb6 Pin
Guffa27-Aug-06 18:24
Guffa27-Aug-06 18:24 
AnswerRe: delete multiple record on access- vb6 Pin
Guffa28-Aug-06 2:03
Guffa28-Aug-06 2:03 
GeneralRe: delete multiple record on access- vb6 Pin
Guffa28-Aug-06 21:56
Guffa28-Aug-06 21:56 
GeneralRe: delete multiple record on access- vb6 Pin
Guffa29-Aug-06 3:43
Guffa29-Aug-06 3:43 
GeneralRe: delete multiple record on access- vb6 Pin
Guffa29-Aug-06 21:25
Guffa29-Aug-06 21:25 
Questionhelp data report AND crystal report Pin
very_short_life27-Aug-06 14:07
very_short_life27-Aug-06 14:07 

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.