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

  • Home
  • SEARCH
  • 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 6184869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:36:49+00:00 2026-05-24T01:36:49+00:00

So from the comments section where this persons code was translated to VB.NET on

  • 0

So from the comments section where this persons code was translated to VB.NET on http://www.codeproject.com/KB/cs/Threadsafe_formupdating.aspx it shows a little code to aid in calling cross thread UI stuff.

<System.Runtime.CompilerServices.Extension()> _
Public Function SafeInvoke(Of T As ISynchronizeInvoke, TResult)(ByRef isi As T, ByRef [call] As Func(Of T, TResult)) As TResult
    If isi.InvokeRequired Then
        Dim result As IAsyncResult = isi.BeginInvoke([call], New Object() {isi})
        Dim endResult As Object = isi.EndInvoke(result)
        Return DirectCast(endResult, TResult)
    Else
        Return [call](isi)
    End If
End Function

When I try to call the following however I get an error:

Me.SafeInvoke(Function(x) x.Close())

or

frmLobby.SafeInvoke(Function(x) x.Close())

Error 1 Data type(s) of the type parameter(s) in extension method ‘Public Function SafeInvoke(Of TResult)(ByRef call As System.Func(Of frmLogin, TResult)) As TResult’ defined in ‘GvE.Globals’ cannot be inferred from these arguments. Specifying the data type(s) explicitly might correct this error. C:\GvE\GvE\frmLogin.vb 37 9 GvE

What am I missing? I’m calling that code from inside a method defined in a form but that method is being called from another thread.

Just trying to avoid delegates and this is what the code above is supposed to do, but just can’t get it to work.

Thanks

  • 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-24T01:36:50+00:00Added an answer on May 24, 2026 at 1:36 am

    Your SafeInvoke method takes a Func(Of T, TResult).
    That’s a function that takes a T and returns a TResult.

    Since x.Close() is a Sub and doesn’t return anything, you can’t make it into a Func(Of T, TResult).

    You should make an overload that takes an Action(Of T) – a sub that takes a T and doesn’t return anything.

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

Sidebar

Related Questions

I would extract some section html code from a string. This string is returned
I'm looking for Python code that removes C and C++ comments from a string.
This question arose from the discussion in the comments of this answer . First,
I'm currently working my way through this book: http://www1.idc.ac.il/tecs/ I'm currently on a section
So, as I learned from Michael Burr 's comments to this answer , the
I have this comments section on my site, and in firefox there is a
I have the following code that shows 5 posts each being the latest from
Something I keep doing is removing comments from a file as I process it.
What’s the best way to remove comments from a PHP file? I want to
Is there an easy way to remove comments from a C/C++ source file without

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.