Click here to Skip to main content
16,010,650 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Page Break for report Pin
Dave Kreskowiak14-Mar-08 9:50
mveDave Kreskowiak14-Mar-08 9:50 
GeneralConfused about ByVal Pin
Kevin Brydon13-Mar-08 6:19
Kevin Brydon13-Mar-08 6:19 
GeneralRe: Confused about ByVal Pin
Christian Graus13-Mar-08 9:57
protectorChristian Graus13-Mar-08 9:57 
GeneralRe: Confused about ByVal Pin
MikeMarq13-Mar-08 10:40
MikeMarq13-Mar-08 10:40 
GeneralRe: Confused about ByVal Pin
Kevin Brydon13-Mar-08 23:14
Kevin Brydon13-Mar-08 23:14 
QuestionOpening database connection Pin
johnjsm13-Mar-08 5:24
johnjsm13-Mar-08 5:24 
GeneralRe: Opening database connection Pin
Christian Graus13-Mar-08 9:58
protectorChristian Graus13-Mar-08 9:58 
QuestionBackground Workers with Asynch TCP Connections [modified] Pin
Chinners13-Mar-08 5:19
Chinners13-Mar-08 5:19 
Hi,

I am trying to use remoting for an application I am writing. One problem with remoting is the timeout is too high if a particular IP address is not found (i.e. the remote machine is not turned on). I also need to check that the remote listener is alive.

My solution to this was to write a small routine that "Pings" the remote object beforehand to see if it was alive. This "Ping" routine uses a s simple async TCP connection, so I can adjust the timeout:

      Private HasResponded As Boolean<br />
      Private Timeout As Integer = 100<br />
<br />
      Private Sub TCPResponded(ByVal ar As System.IAsyncResult)<br />
         HasResponded = True<br />
      End Sub<br />
<br />
      Public Function IsAlive(ByVal IPAddress As String) As Boolean<br />
         Dim Conn As New AsyncCallback(AddressOf TCPResponded)<br />
         Dim Tcp As New System.Net.Sockets.TcpClient()<br />
         Dim MyTimeOut As Integer = Timeout<br />
         HasResponded = False<br />
         Tcp.BeginConnect(IPAddress, 9000, Conn, Nothing)<br />
<br />
         While HasResponded = False And MyTimeOut > 0<br />
            System.Threading.Thread.Sleep(10)<br />
            MyTimeOut -= 1<br />
         End While<br />
<br />
         If Tcp.Connected Then<br />
            Tcp.Close()<br />
            Return True<br />
         Else<br />
            Tcp.Close()<br />
            Return False<br />
         End If<br />
      End Function<br />


This class works fine when in the UI thread - it can tell me if a machine is alive or not within a second (I am only dealing with local ethernet, so one second is considered slow).

However, in my UI, I would like an icon to display the status of the remote machine. I thought I could write a simple background worker to call the above code. However, on the TCP.BeginConnect, I get the following error:

System.Net.Sockets.SocketException was unhandled by user code<br />
  ErrorCode=10045<br />
  Message="The attempted operation is not supported for the type of object referenced"<br />
  Source="System"<br />
  StackTrace:<br />
       at System.Net.Sockets.Socket.DoMultipleAddressConnectCallback(Object result, MultipleAddressConnectAsyncResult context)<br />
       at System.Net.Sockets.Socket.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state)<br />
       at System.Net.Sockets.TcpClient.BeginConnect(String host, Int32 port, AsyncCallback requestCallback, Object state)<br />
<snip><br />
</snip>

Has anyone tried an Async connect within a background worker before, and got it working? I have tried googling this, but cant find anything that looks vaguely similar to my problem. As of yesterday, I had not even tried the beginconnect command, so dont really know all the details about it.

Thanks in advance.

Jason

modified on Thursday, March 13, 2008 12:59 PM

GeneralVISTA AREO in VB.NET Pin
vbbeg13-Mar-08 4:31
vbbeg13-Mar-08 4:31 
GeneralRe: VISTA AREO in VB.NET Pin
Colin Angus Mackay13-Mar-08 5:06
Colin Angus Mackay13-Mar-08 5:06 
GeneralRe: VISTA AREO in VB.NET Pin
vbbeg13-Mar-08 20:37
vbbeg13-Mar-08 20:37 
GeneralRe: VISTA AREO in VB.NET Pin
Colin Angus Mackay13-Mar-08 23:06
Colin Angus Mackay13-Mar-08 23:06 
Questionrun time error please help Pin
asha_s13-Mar-08 4:06
asha_s13-Mar-08 4:06 
GeneralRe: run time error please help Pin
Chinners13-Mar-08 6:11
Chinners13-Mar-08 6:11 
GeneralRe: run time error please help Pin
asha_s13-Mar-08 10:02
asha_s13-Mar-08 10:02 
GeneralSpeed Up OleDbDataAdapter.Update() Pin
A Wong13-Mar-08 3:54
A Wong13-Mar-08 3:54 
GeneralRe: Speed Up OleDbDataAdapter.Update() Pin
Dave Kreskowiak14-Mar-08 8:20
mveDave Kreskowiak14-Mar-08 8:20 
GeneralRe: Speed Up OleDbDataAdapter.Update() Pin
A Wong14-Mar-08 8:26
A Wong14-Mar-08 8:26 
GeneralRe: Speed Up OleDbDataAdapter.Update() Pin
Dave Kreskowiak14-Mar-08 10:04
mveDave Kreskowiak14-Mar-08 10:04 
GeneralRe: Speed Up OleDbDataAdapter.Update() Pin
A Wong14-Mar-08 10:10
A Wong14-Mar-08 10:10 
GeneralRe: Speed Up OleDbDataAdapter.Update() Pin
Dave Kreskowiak14-Mar-08 12:18
mveDave Kreskowiak14-Mar-08 12:18 
GeneralRe: Speed Up OleDbDataAdapter.Update() Pin
A Wong17-Mar-08 2:08
A Wong17-Mar-08 2:08 
GeneralSpace between Custom scrollbars horizontal & vertical Pin
VB 8.013-Mar-08 2:24
VB 8.013-Mar-08 2:24 
GeneralI need help on my School Work..........E-Doctor for my School Medical Centre Pin
ak47angel13-Mar-08 1:41
ak47angel13-Mar-08 1:41 
GeneralRe: I need help on my School Work..........E-Doctor for my School Medical Centre Pin
Colin Angus Mackay13-Mar-08 1:54
Colin Angus Mackay13-Mar-08 1:54 

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.