Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7403601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:07:47+00:00 2026-05-29T05:07:47+00:00

I am trying to start a thread in a form for a function that

  • 0

I am trying to start a thread in a form for a function that takes about 5 seconds to run so I can keep the UI from locking up. I have the following code below, but it fails when it hits “thread1.start.” When I watch it though a debugger it just goes strait to “End Sub” and it does not go to the getSecurityStuff() method that I am expecting it to go to. Any ideas?

Thanks!

Imports System.Threading

Public Class frmAddAssets

    Private theDict As Dictionary(Of String, String) = Nothing


    Private Sub frmAddAssets_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Control.CheckForIllegalCrossThreadCalls = False

    End Sub

    Private Sub cmbTickerEntry_Leave(sender As System.Object, e As System.EventArgs) Handles cmbTickerEntry.Leave

        Dim thread1 As New Thread(New ThreadStart(AddressOf getSecurityStuff))

        thread1.Start()

    End Sub

    Public Sub getSecurityStuff()

        Dim getData As New clsSecurityView(cmbTickerEntry.Text())

        Try
            theDict = getData.getStockData()
        Catch ex As Exception
            Throw
        End Try

        filldata()

    End Sub

    Private Sub filldata()

        Dim list As New List(Of String)(theDict.Keys)

        txtTicker.Text = cmbTickerEntry.Text.ToString()

        For Each kvp As KeyValuePair(Of String, String) In theDict

            Select Case True
                Case kvp.Key = "Name"
                    txtSecurityName.Text = kvp.Value.ToString()
                Case kvp.Key = "Price"
                    txtPrice.Text = kvp.Value.ToString()
                Case kvp.Key = "Market Capitalization"
                    txtMarketCap.Text = kvp.Value.ToString()
                Case kvp.Key = "Dividend Yield"
                    txtDivYield.Text = kvp.Value.ToString()
                Case kvp.Key = "PE Ratio"
                    txtPERatio.Text = kvp.Value.ToString()
                Case kvp.Key = "EPS"
                    txtEPS.Text = kvp.Value.ToString()
            End Select

        Next

    End Sub
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:07:48+00:00Added an answer on May 29, 2026 at 5:07 am

    …When I watch it though a debugger it just goes strait to “End
    Sub”…

    Please note that thread1.Start() won’t block the current thread.

    Setting CheckForIllegalCrossThreadCalls to False won’t do anything, but ignore the exception(s) that’s throwen, when you access the properties of a control owned by the UI thread – which also is your problem:

    • You create a new thread
    • The new thread calls getSecurityStuff
    • You try to declare a new clsSecurityView, with cmbTickerEntry.Text as parameter.
    • EXCEPTION – you try to access a control owned by the UI thread, while being on another thread!
    • No exception shows up, because you’ve set CheckForIllegalCrossThreadCalls to False

    Same deal with fillData… trying to access controls outside the UI thread.

    Solution: Use Invoke/BeginInvoke to execute code that should read/modify properties on controls owned by the UI thread.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to start a winForm from a thread, but when i do
How can I start a thread which will run in the background but the
I am trying to create a second thread with dispatcher so that I can
I'm trying to run an ATM Simulation in C# with Windows Forms that can
I am trying to create a thread that contains a form progress bar (just
I have two threads that are declared global.On the form load i start the
I am trying to start a service from the command line using net start
I'm trying to start a service that has a argument that specifies a port
I'm just trying to run a new thread each time a button click even
I have a Windows Form app that creates a window and monitors for entries

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.