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 8909581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:28:00+00:00 2026-06-15T03:28:00+00:00

Whenever I call the constructor of the following Structure ( with the parameter set

  • 0

Whenever I call the constructor of the following Structure (with the parameter set to True) I get a NullReferenceException:

Imports System.Threading
Imports System.Windows.Threading

Public Structure Test

  Private MyDispatcher As Dispatcher
  Private MyResetEvent As ManualResetEvent

  Public Sub New(ByVal newThread As Boolean)
    If newThread Then
      MyResetEvent = New ManualResetEvent(False)
      Dim thread As New Thread(AddressOf Start)
      thread.Start()
      MyResetEvent .WaitOne()

      ' NullReferenceException below:
      MyDispatcher.BeginInvoke(New Action(AddressOf DoSomething))
    End If
  End Sub

  Private Sub Start()
    MyDispatcher = Dispatcher.CurrentDispatcher
    MyResetEvent.Set()
    Dispatcher.Run()
  End Sub

  Private Sub DoSomething()
  End Sub
End Structure

MyDispatcher is Nothing, which causes the NullReferenceException. But using a Class instead of a Structure works just fine. Why?

Edit: And what workarounds are possible?

  • 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-06-15T03:28:02+00:00Added an answer on June 15, 2026 at 3:28 am

    The problem is the delegate that is constructed when you use AddressOf. Delegates are constructed using an Object reference (for instance methods). The structure, necessarily, is boxed when it is passed as an Object, and will be unboxed before Start is called. It is this second, unboxed, copy of your structure that the Start method mutates.

    Your original code, still working with the unboxed original structure, will see no modifications.

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

Sidebar

Related Questions

Whenever I call my logger in a method, e.g. _logger.Debug(Connecting to database...); I get
I am using following function. Whenever i call it that time it will increase
whenever I try to call my ejb from a client, I get this error
I would like to mock the Date constructor so that whenever I call new
Whenever I call trigger(reloadGrid) on a JqGrid, it clears the existing table, displays a
I keep getting this error whenever I call gethostbyname() in my C code. ==7983==
I'm working on a Perl module and whenever I call the skip() method I
I'm using the facebook graph PHP sdk - whenever I call the $facebook->api method
Save one image path in the database... and whenever a call is made to
I have two Activities along with one Application class, and whenever I call my

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.