473,320 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

threading timer advice?

I’d like to control the threading for these lines of vb.net code:

udpClient.Send(bytcmd, bytcmd.Length, remoteEP) 'send recordset0

Dim InBuf As Byte() = {}
If InBuf.Length > 0 Then
If ReceiveTestBlock(InBuf) = True Then
Return True
End If
End If

udpClient.Close()

Any advice appreciated.

Regards;

Segue

Jun 5 '06 #1
4 1266
Segue,

You will need to elaborate. From what I can tell, there is no
threading. I see a user-defined method (RecieveTestBlock), but who can tell
what is in it?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"segue" <se***@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
I'd like to control the threading for these lines of vb.net code:

udpClient.Send(bytcmd, bytcmd.Length, remoteEP) 'send recordset0

Dim InBuf As Byte() = {}
If InBuf.Length > 0 Then
If ReceiveTestBlock(InBuf) = True Then
Return True
End If
End If

udpClient.Close()

Any advice appreciated.

Regards;

Segue


Jun 5 '06 #2
Thanks for the quick response and I apologize for a lack of code and expertise.

My program hangs on the receive (pasted below), when I'm trying to connect
to a computer with the wrong IP or the computer is not responding due to a
mode that it is in. If I could I'd place a try catch to abort whatever
asynchronous runtime environment is going on regarding the net socket
udpclient, then that would be ideal. But a try catch doesn't work so I feel
I need to control the receive by binding it to a thread somehow.

To get to this udpclient send processing I'm instantiating another class
before it and passing variables from an event triggered from a windows form
application. I've got a coding example where I can sleep or abort a class
after binding it to a thread but this example is independent of passing
variables.

Function ReceiveTestBlock(ByVal inbuf As Byte()) As Boolean

Dim i As Integer
Dim newbyte As Byte

For i = 0 To inbuf.Length - 1
newbyte = inbuf(i)

If i = 3 Then
If newbyte = &HFBS Then

Return True
End If
End If
Next i
End Function

"Nicholas Paldino [.NET/C# MVP]" wrote:
Segue,

You will need to elaborate. From what I can tell, there is no
threading. I see a user-defined method (RecieveTestBlock), but who can tell
what is in it?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"segue" <se***@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
I'd like to control the threading for these lines of vb.net code:

udpClient.Send(bytcmd, bytcmd.Length, remoteEP) 'send recordset0

Dim InBuf As Byte() = {}
If InBuf.Length > 0 Then
If ReceiveTestBlock(InBuf) = True Then
Return True
End If
End If

udpClient.Close()

Any advice appreciated.

Regards;

Segue



Jun 5 '06 #3
segue,
UdpClient will just site there if there is no connection. As Nick pointed
out, using a timer will not solve this problem.
What you need to do is either derive from UdpClient so that you can gain
access to the underlying socket, or use the socket class. The pattern is
basically that you would set a timed WaitCallback or delegate that accepts an
instance of the socket, does it timing thing, and when it's elapsed if the
socket is not null it would close the socket.

If you search around on something like "UdpTimeout Class" you may be able to
find one or two decent implementations of the concept.
hope that helps.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"segue" wrote:
Thanks for the quick response and I apologize for a lack of code and expertise.

My program hangs on the receive (pasted below), when I'm trying to connect
to a computer with the wrong IP or the computer is not responding due to a
mode that it is in. If I could I'd place a try catch to abort whatever
asynchronous runtime environment is going on regarding the net socket
udpclient, then that would be ideal. But a try catch doesn't work so I feel
I need to control the receive by binding it to a thread somehow.

To get to this udpclient send processing I'm instantiating another class
before it and passing variables from an event triggered from a windows form
application. I've got a coding example where I can sleep or abort a class
after binding it to a thread but this example is independent of passing
variables.

Function ReceiveTestBlock(ByVal inbuf As Byte()) As Boolean

Dim i As Integer
Dim newbyte As Byte

For i = 0 To inbuf.Length - 1
newbyte = inbuf(i)

If i = 3 Then
If newbyte = &HFBS Then

Return True
End If
End If
Next i
End Function

"Nicholas Paldino [.NET/C# MVP]" wrote:
Segue,

You will need to elaborate. From what I can tell, there is no
threading. I see a user-defined method (RecieveTestBlock), but who can tell
what is in it?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"segue" <se***@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
I'd like to control the threading for these lines of vb.net code:

udpClient.Send(bytcmd, bytcmd.Length, remoteEP) 'send recordset0

Dim InBuf As Byte() = {}
If InBuf.Length > 0 Then
If ReceiveTestBlock(InBuf) = True Then
Return True
End If
End If

udpClient.Close()

Any advice appreciated.

Regards;

Segue



Jun 5 '06 #4
Thanks so much for understanding my greenish problem.

I found this to the point article:
http://www.vbcity.com/forums/topic.asp?tid=109375

Cheers

"Peter Bromberg [C# MVP]" wrote:
segue,
UdpClient will just site there if there is no connection. As Nick pointed
out, using a timer will not solve this problem.
What you need to do is either derive from UdpClient so that you can gain
access to the underlying socket, or use the socket class. The pattern is
basically that you would set a timed WaitCallback or delegate that accepts an
instance of the socket, does it timing thing, and when it's elapsed if the
socket is not null it would close the socket.

If you search around on something like "UdpTimeout Class" you may be able to
find one or two decent implementations of the concept.
hope that helps.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"segue" wrote:
Thanks for the quick response and I apologize for a lack of code and expertise.

My program hangs on the receive (pasted below), when I'm trying to connect
to a computer with the wrong IP or the computer is not responding due to a
mode that it is in. If I could I'd place a try catch to abort whatever
asynchronous runtime environment is going on regarding the net socket
udpclient, then that would be ideal. But a try catch doesn't work so I feel
I need to control the receive by binding it to a thread somehow.

To get to this udpclient send processing I'm instantiating another class
before it and passing variables from an event triggered from a windows form
application. I've got a coding example where I can sleep or abort a class
after binding it to a thread but this example is independent of passing
variables.

Function ReceiveTestBlock(ByVal inbuf As Byte()) As Boolean

Dim i As Integer
Dim newbyte As Byte

For i = 0 To inbuf.Length - 1
newbyte = inbuf(i)

If i = 3 Then
If newbyte = &HFBS Then

Return True
End If
End If
Next i
End Function

"Nicholas Paldino [.NET/C# MVP]" wrote:
Segue,

You will need to elaborate. From what I can tell, there is no
threading. I see a user-defined method (RecieveTestBlock), but who can tell
what is in it?

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"segue" <se***@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
> I'd like to control the threading for these lines of vb.net code:
>
> udpClient.Send(bytcmd, bytcmd.Length, remoteEP) 'send recordset0
>
> Dim InBuf As Byte() = {}
> If InBuf.Length > 0 Then
> If ReceiveTestBlock(InBuf) = True Then
> Return True
> End If
> End If
>
> udpClient.Close()
>
> Any advice appreciated.
>
> Regards;
>
> Segue
>
>
>
>
>

Jun 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
2
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using...
6
by: whtinkm | last post by:
Hi, All Recently, my project need some code like following: using System; using System.Threading; namespace MyTimerTest { class Class1 {
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
0
by: Kelsang Wangchuk | last post by:
Hi Just a quick question... When would you use System.Timers.Timer, and when System.Threading.Timer? What are the principal differences between them? There is a lot of discussion about...
8
by: NewUser | last post by:
Hello, I'm a new user to Visual Basic.net and I would appreciate any help regarding a problem I have. I have searched the posts in this newsgroup and the VB library for threading topics, but I...
7
by: melton9 | last post by:
I have a web service that I believe needs to implement threading. I have a timer setup to fire 3 requests and have them do some calculations and send the info to the mainform. I also need the...
8
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.