Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Threading Question

I have a VB .NET windows application that I spawns a thread to send to a web service. The problem I'm having is that some of the values that the thread needs come from text and combo boxes. When I use threading sometimes the text values appear empty "" 
When I turn off the threading and do it the 'old-fasion' everything works great.

any ideas ?

Tom
0
thenrich
Asked:
thenrich
  • 2
1 Solution
 
S-TwilleyCommented:
I tend to wrap threads which need values in their own class... so something like this (it's a bit rushed):

Public Class ThreadWrapper
    Public myText As String
    Public myInt As Integer
    Private thisThread As Threading.Thread

    Public Sub New(ByVal NewText As String, ByVal NewInt As Integer)
        myText = NewText
        myInt = NewInt
    End Sub

    Public Sub Start()
        thisThread = New Threading.Thread(AddressOf threadStart)
        thisThread.Start()
    End Sub

    Private Sub threadStart()

        'your code here using the values myText and myInt

        RaiseEvent ThreadFinished(Me)
    End Sub

    Public Event ThreadFinished(ByVal sender As ThreadWrapper)
End Class

==================

Then in your form somewhere...

Dim myThread as new ThreadWrapper(Combobox1.Text, 123)
AddHandler myThread.ThreadFinished, AddressOf MyThreadHandler
myThread.Start


Then somewhere else in your form.. add the handler for the event finished  (it's not necessary but you'll probably want to capture when it's finished)

Sub MyThreadHandler(sender as ThreadWrapper)
      ' handle the event
End Sub
0
 
thenrichAuthor Commented:
I'll give it a shot !!!
0
 
thenrichAuthor Commented:
Good coding form and good idea!
thx
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now