?
Solved

Threading Question

Posted on 2005-03-28
3
Medium Priority
?
190 Views
Last Modified: 2010-04-23
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
Comment
Question by:thenrich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
S-Twilley earned 2000 total points
ID: 13644128
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
 
LVL 5

Author Comment

by:thenrich
ID: 13644148
I'll give it a shot !!!
0
 
LVL 5

Author Comment

by:thenrich
ID: 13644653
Good coding form and good idea!
thx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question