Jump to content
Xtreme .Net Talk

Threading and the timer, problem.


Recommended Posts

Posted

I have created a UDP sockets class. But theres a fundamental flaw in the class.

 

When the UDPclient is listening for a reply from the server it hangs my program if no reply is sent. I got over this by running the udpsend in another thread. Great but now I have a thread that needs killing. I thought of using the timer the kill the thread if it didnt repond in the alloted time, but apparently timers only work in a single threaded environment.

 

Has anyone got any suggestions of how to get around this problem?

 

Strange to think that with VB6 this task was done easily within 5 mins (this is my 3rd day in VB.NET!

 

Imogen

 

PS before you suggest using a TCP client server with a definite connection state, I cant the server is pre-written and I do not have the source code to authority to change it.

 

Also I could use the VB6 OCX to achieve the desired result... but feel I shouldnt have to, should I be able to do it just as well (if not better in .NET)

  • Administrators
Posted

Do you want the thread to kill itself after a certain time or just exit when the main thread is terminated?

 

If you just want to prevent the thread keeping your app alive setting the thread's IsBackGround property to true will cause it to be terminate when your app's main thread shuts down.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • *Gurus*
Posted

Timers work regardless of the number of threads in your application.

 

'Create the delegate that invokes methods for the timer.
Dim timerDelegate As New TimerCallback(AddressOf CheckStatus)
     
'Create a timer that waits one second, then invokes every second.
Dim timer As New Timer(timerDelegate, s, 1000, 1000)

 

To terminate a thread you call:

myThread.Abort()

Posted

Thanks, although since writing my request I have found out that an Asynchronos version of the UDP socket can be created. Has anyone got any information on this ?

 

Thanks again

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...