PC Review


Reply
Thread Tools Rate Thread

How do I start and stop threads from the GUI?

 
 
Russ Ryba
Guest
Posts: n/a
 
      10th Dec 2004
I'm working on a threaded socket server for PPC. The problem I'm having
is I can't seem to start and stop the socket from the GUI. I'm sure
there is something required with Invoke, but I am not sure where to start.

I want to listen when a toolbar button is pushed, and stop listening
when the toolbar button is pushed again. I think the listener may have
to poll the toolbar button state. I'm unclear if the listening thread
can READ control properties directly, or if they need to synclock or
invoke things too.

Right now it works like this. (OK, it doesn't work at all like this.)

-----------------------------------------------------------------------
Private Sub ToolBar1_ButtonClick(...) Handles ToolBar1.ButtonClick
'Evaluate the Button property to determine which
' button was clicked.
Select Case ToolBar1.Buttons.IndexOf(e.Button)
Case 0 'Connect
If e.Button.Pushed Then
Debug.WriteLine("Start Listening")
StartListening()
Else
Debug.WriteLine("Stop Listening")
StopListening()
End If
End Select
End Sub

Private Sub StartListening()
If ListenerThread Is Nothing Then
ListenerThread = New Thread(AddressOf IHearYa)
End If
Try
ListenerThread.Start()
Catch ex As Exception
Debug.WriteLine("Error in StartListening, " & ex.Message _
& vbCrLf & ex.ToString)
End Try
End Sub

Private Sub StopListening()
Try
'Kill the thread by setting it to nothing
' Will this work?
ListenerThread = Nothing
Catch ex As Exception
Debug.WriteLine("Exception in stopListening, " & _
ex.Message & vbCrLf & ex.ToString)
End Try
End Sub

Private Sub IHearYA()
'Starts a Socket
'Listen
'Bind
'Repeat until Toolbar button.pushed is false
End Sub
-------------------------------------------------------------

Show me the error of my ways, oh ye of great big brains.

- Russ
 
Reply With Quote
 
 
 
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      10th Dec 2004
Do not kill threads. Stop threads gracefully by setting a flag that is
checked in the thread proc.

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Russ Ryba" <(E-Mail Removed)> wrote in message
news:uB$(E-Mail Removed)...
> I'm working on a threaded socket server for PPC. The problem I'm having
> is I can't seem to start and stop the socket from the GUI. I'm sure there
> is something required with Invoke, but I am not sure where to start.
>
> I want to listen when a toolbar button is pushed, and stop listening when
> the toolbar button is pushed again. I think the listener may have to poll
> the toolbar button state. I'm unclear if the listening thread can READ
> control properties directly, or if they need to synclock or invoke things
> too.
>
> Right now it works like this. (OK, it doesn't work at all like this.)
>
> -----------------------------------------------------------------------
> Private Sub ToolBar1_ButtonClick(...) Handles ToolBar1.ButtonClick
> 'Evaluate the Button property to determine which
> ' button was clicked.
> Select Case ToolBar1.Buttons.IndexOf(e.Button)
> Case 0 'Connect
> If e.Button.Pushed Then
> Debug.WriteLine("Start Listening")
> StartListening()
> Else
> Debug.WriteLine("Stop Listening")
> StopListening()
> End If
> End Select
> End Sub
>
> Private Sub StartListening()
> If ListenerThread Is Nothing Then
> ListenerThread = New Thread(AddressOf IHearYa)
> End If
> Try
> ListenerThread.Start()
> Catch ex As Exception
> Debug.WriteLine("Error in StartListening, " & ex.Message _
> & vbCrLf & ex.ToString)
> End Try
> End Sub
>
> Private Sub StopListening()
> Try
> 'Kill the thread by setting it to nothing
> ' Will this work?
> ListenerThread = Nothing
> Catch ex As Exception
> Debug.WriteLine("Exception in stopListening, " & _
> ex.Message & vbCrLf & ex.ToString)
> End Try
> End Sub
>
> Private Sub IHearYA()
> 'Starts a Socket
> 'Listen
> 'Bind
> 'Repeat until Toolbar button.pushed is false
> End Sub
> -------------------------------------------------------------
>
> Show me the error of my ways, oh ye of great big brains.
>
> - Russ



 
Reply With Quote
 
Guest
Posts: n/a
 
      10th Dec 2004
Depends on how you want it to work, but if you use the ThreadEx class from
OpenNETCF you can pause and resume a thread. That's probably the best bet.

-Chris


"Russ Ryba" <(E-Mail Removed)> wrote in message
news:uB$(E-Mail Removed)...
> I'm working on a threaded socket server for PPC. The problem I'm having
> is I can't seem to start and stop the socket from the GUI. I'm sure there
> is something required with Invoke, but I am not sure where to start.
>
> I want to listen when a toolbar button is pushed, and stop listening when
> the toolbar button is pushed again. I think the listener may have to poll
> the toolbar button state. I'm unclear if the listening thread can READ
> control properties directly, or if they need to synclock or invoke things
> too.
>
> Right now it works like this. (OK, it doesn't work at all like this.)
>
> -----------------------------------------------------------------------
> Private Sub ToolBar1_ButtonClick(...) Handles ToolBar1.ButtonClick
> 'Evaluate the Button property to determine which
> ' button was clicked.
> Select Case ToolBar1.Buttons.IndexOf(e.Button)
> Case 0 'Connect
> If e.Button.Pushed Then
> Debug.WriteLine("Start Listening")
> StartListening()
> Else
> Debug.WriteLine("Stop Listening")
> StopListening()
> End If
> End Select
> End Sub
>
> Private Sub StartListening()
> If ListenerThread Is Nothing Then
> ListenerThread = New Thread(AddressOf IHearYa)
> End If
> Try
> ListenerThread.Start()
> Catch ex As Exception
> Debug.WriteLine("Error in StartListening, " & ex.Message _
> & vbCrLf & ex.ToString)
> End Try
> End Sub
>
> Private Sub StopListening()
> Try
> 'Kill the thread by setting it to nothing
> ' Will this work?
> ListenerThread = Nothing
> Catch ex As Exception
> Debug.WriteLine("Exception in stopListening, " & _
> ex.Message & vbCrLf & ex.ToString)
> End Try
> End Sub
>
> Private Sub IHearYA()
> 'Starts a Socket
> 'Listen
> 'Bind
> 'Repeat until Toolbar button.pushed is false
> End Sub
> -------------------------------------------------------------
>
> Show me the error of my ways, oh ye of great big brains.
>
> - Russ



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PC power on - start, stop, start, stop, etc - eventually powers up spodosaurus DIY PC 10 27th Dec 2008 02:55 PM
Initiating Threads on IIS Start Up John Microsoft ASP .NET 2 28th Feb 2006 04:15 PM
Start 20 Threads, stop them all after 10 seconds Mark B Microsoft ASP .NET 7 21st Jun 2005 04:33 PM
Start 20 Threads, stop them all after 10 seconds Mark B Microsoft VB .NET 7 21st Jun 2005 04:33 PM
stop or reduce some threads Peter Seiler Freeware 8 23rd Aug 2004 02:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:49 PM.