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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:45:13+00:00 2026-05-14T02:45:13+00:00

I am trying to write a VB.NET alternative to a C# anonymous function. I

  • 0

I am trying to write a VB.NET alternative to a C# anonymous function.

I wish to call Threading.SynchronizationContext.Current.Send which expects a delegate of type Threading.SendOrPostCallback to be passed to it. The background is here, but because I wish to both pass in a string to MessageBox.Show and also capture the DialogResult I need to define another delegate within. I am struggling with the VB.NET syntax, both from the traditional delegate style, and lambda functions.

My go at the traditional syntax is below, but I have gut feeling it should be much simpler than this:

Private Sub CollectMesssageBoxResultFromUserAsDelegate(ByVal messageToShow As String, ByRef wasCanceled As Boolean)
    wasCanceled = False
    If Windows.Forms.MessageBox.Show(String.Format("{0}{1}Please press [OK] to ignore this error and continue, or [Cancel] to stop here.", messageToShow), "Continue", Windows.Forms.MessageBoxButtons.OKCancel, Windows.Forms.MessageBoxIcon.Exclamation) = Windows.Forms.DialogResult.Cancel Then
        wasCanceled = True
    End If
End Sub


Private Delegate Sub ShowMessageBox(ByVal messageToShow As String, ByRef canceled As Boolean)


Private Sub AskUserWhetherToCancel(ByVal message As String, ByVal args As CancelEventArgs)

    If args Is Nothing Then args = New System.ComponentModel.CancelEventArgs With {.Cancel = False}

    Dim wasCancelClicked As Boolean
    Dim firstDelegate As New ShowMessageBox(AddressOf CollectMesssageBoxResultFromUserAsDelegate)
    '…. Now what??
    'I can’t declare SendOrPostCallback as below: 
    'Dim myDelegate As New Threading.SendOrPostCallback(AddressOf firstDelegate) 


End Sub
  • 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-14T02:45:13+00:00Added an answer on May 14, 2026 at 2:45 am

    I think the easiest way to handle this is to create a new object which wraps the displaying of the message box. This object can then be used to retrieve the result.

    For example:

    Public Class Helper 
      Public WasCanceled as Boolean
      Public Message As String
      Public Done as New ManualResetEvent(false)
      Public Sub New(message as String) 
        Me.Message = message
      End Sub 
      Public Sub ShowMessageBox(unused as Object) 
        If MessageBox.Show(Message) = DialogResult.Cancel Then 
          WasCanceled = True
        Done.Set()
      End Sub 
    End Class
    
    Public Sub AskUserWhetherToCancel(context as SynchronizationContext, message As String)
      Dim helper As New Helper(message)
      context.Post(AddressOf helper.ShowMessageBox, Nothing)
    
      ' Wait for it to finish
      helper.WaitOne()
    
      if helper.WasCanceled Then 
        ...
      Else
        ...
      End IF
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple website (ASP.NET v4), which will call Windows Search,
I'm trying to write a re-usable .NET Assembly that implements WCF. My current problem
I am trying to write code to send a simple mail from asp.net page.
I am playing around with Asp.net MVC2 and trying to write a page which
I am trying to write a web service in ASP.NET which enables an outside
I am trying to write an ASP.NET MVC application which is a frontend to
I'm trying to write a custom ASP.NET field validator which makes sure the input
I'm currently trying to write a program in VB.NET which fluidly changes the DWM
I'm trying to write an ASP.NET MVC application where user privilege is based upon
I'm trying to write a web page in .NET, using C# and NHibernate 2.1.

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.