473,748 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threading with Network.Ping

17 New Member
Hi Guys,

I have used Threading for Network.Ping to continuously ping an IP address if ping is successful Image A is displayed if not Image B. The code is as follows:

Expand|Select|Wrap|Line Numbers
  1. Imports System
  2. Imports System.Diagnostics
  3. Imports System.Threading
  4.  
  5. Public Class Form1
  6.  
  7.     Dim PingThread As Thread
  8.     Dim PRes
  9.  
  10.  
  11.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  12.  
  13.         PingThread = New Thread(AddressOf Me.BackgroundProcess)
  14.         PingThread.Start()
  15.  
  16.     End Sub
  17.  
  18.     Private Sub BackgroundProcess()
  19.  
  20.         Dim IPAddress As String = "192.168.1.121"
  21.  
  22.         Do
  23.             If My.Computer.Network.Ping(IPAddress) = True Then
  24.  
  25.                 PRes = True
  26.             Else
  27.                 PRes = False
  28.             End If
  29.  
  30.             Application.DoEvents()
  31.             Thread.Sleep(1000)
  32.  
  33.         Loop
  34.  
  35.  
  36.     End Sub
  37.  
  38.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  39.  
  40.         If PRes = True Then
  41.             PictureBox1.Visible = True
  42.             PictureBox2.Visible = False
  43.         Else
  44.             If PRes = False Then
  45.                 PictureBox1.Visible = False
  46.                 PictureBox2.Visible = True
  47.             End If
  48.         End If
  49.  
  50.  
  51.     End Sub
  52.  
  53. End Class
  54.  
However i have only been able to change the images on a button click. What i want to do is just run my app and for the Images to change automatically without any input. The code below (Not using Threading) allows this to happen, although it is first initiated by a button click.

Expand|Select|Wrap|Line Numbers
  1. Imports System
  2. Imports System.Diagnostics
  3.  
  4.  
  5. Public Class Form1
  6.  
  7.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8.  
  9.     End Sub
  10.  
  11.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  12.         Dim IPAddress As String = "192.168.1.121"
  13.  
  14.         Do
  15.  
  16.             If My.Computer.Network.Ping(IPAddress) = True Then
  17.  
  18.                 PictureBox1.Visible = False
  19.                 PictureBox2.Visible = True
  20.             Else
  21.                 PictureBox1.Visible = True
  22.                 PictureBox2.Visible = False
  23.  
  24.             End If
  25.  
  26.             Application.DoEvents()
  27.             System.Threading.Thread.Sleep(10)
  28.  
  29.  
  30.         Loop
  31.     End Sub
  32.  
  33. End Class
  34.  
Ive been looking at my code for hours...i know it must be obvious!!! Thanks in advance guys


Sy
Mar 3 '08 #1
0 1481

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1826
by: Eddy_w | last post by:
Hello, I try to ping from my mobile device with a wireless connection to my pc. I found the class clsping on the internet and it works perfect with application from pc to pc but when i use it from mobile device (win ce.net 4.2) to pc then it doesn't work anymore. I get on error on the following statement: Dim sckSocket As New System.Net.Sockets.Socket( _
1
1074
by: CEBreedlove | last post by:
I'm trying to trow in another thread into my program. What it's for is to ping a list of IPs. When it runs the Ping portion of the code, it assigns a value of 1 or 2 (pingable / not pingable) to a global int. It works great, however it's slow... If I run the ping portion of my code in a thread, it returns random values for the pingable / non pingable values... My code and a screenshot of is located here....
5
3429
by: Brett Romero | last post by:
I'm running the code below to get network paths. DirectoryInfo diSource = new DirectoryInfo( fullPath ); They usually look like this: \\cpx-270\SomeFolder I may or may not have access to SomeFolder. Sometimes the machine isn't on or the folder is spelled "SomeFolders" on a particular
18
18751
by: NEWSGROUPS | last post by:
I work for a large organization were my team has developed 2 very substantial databases in Access 2000. These databases have been working fine for the last 6 years with minimal issues or problems. About 1 week ago today we have started experiencing the error "Microsoft Visual Basic Run Time Error 3043 Disk or Network Error" just about every day around the same time each day (activity starts to increase at this time in the databases)....
4
1598
by: cj | last post by:
How would you suggest I test that my network drive is still up and running. Right now I'm going to write to a file at the root of the drive and then read it back in. If either the write or read fail I figure the network is down. Any better ideas?
14
2990
by: Omar Abid | last post by:
Hi, I'm using my with a program to detect an internet connection. It return true when I'm connected, but even when I 'm disconnected it returns true I don't know why ? Thx Omar Abid
3
11871
by: SyGC | last post by:
Hi People, Im trying to do a simple Loop where by an IP address is pinged (Using My.computer.network.ping) and the results, true or false, are used to invoke another line of code. Basically if the IP is pingable (true) image A is displayed if it is not (false) then image B is. The code i am using is as follows Dim IPAddress As String = "192.168.1.122"
2
4182
Motoma
by: Motoma | last post by:
Hello everyone, I am having a tiny problem putting together a small script. I tried throwing together a multi-threaded ping utility, but the threads are not behaving the way I anticipated...Perhaps one of you could look and see why this is happening. Python 2.5.2, Ubuntu 8.04 #! /usr/bin/env python import os, sys, threading
1
2565
by: somsub | last post by:
Can any one help me on ping command . for this line of code ($ret, $duration, $ip) = $p->ping ($line) If i give any 1> invalid entry as a parameter ($line) in ping command or
0
8994
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9250
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4878
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.