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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:18:24+00:00 2026-05-19T00:18:24+00:00

Sorry for long title, I don’t know even the way on how to express

  • 0

Sorry for long title, I don’t know even the way on how to express the question

I’m using a library which run a callback from a different context from the main thread (is a C Library), I created the callback in C# and when gets called I would like to just raise an event.

However because I don’t know what will be inside the event, I would like to find a way to invoke the method without the problem of locks and so on (otherwise the third party user will have to handle this inside the event, very ugly)

Are there any way to do this?
I can be totally on the wrong way but I’m thinking about winforms way to handle different threads (the .Invoke thing)

Otherwise I can send a message to the message loop of the window, but I don’t know a lot about message passing and if I can send “custom” messages like this

Example:

private uint lgLcdOnConfigureCB(int connection, System.IntPtr pContext)
{
    OnConfigure(EventArgs.Empty);
    return 0U;
}

this callback is called from another program which I don’t have control over, I would like to run OnConfigure method in the main thread (the one that handles my winform), how to do it?
Or in other words, I would like to run OnConfigure without the need of thinking about locks

Edit 1:

I have a problem with this exception:

CallbackOnCollectedDelegate retrived
Message: Callback run on delegate ‘G19dotNet!G19dotNet.LgLcd+lgLcdOnSoftButtonsCB::Invoke’ collected in GarbageCollector. During unmanaged code delegates should be ensured will never be deleted until you are sure they will never be called

Edit 2:

Issue resolved by myself, thanks to Stackoverflow which always helps me!
For future reference: Defining a delegate as a function pointer

  • 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-19T00:18:25+00:00Added an answer on May 19, 2026 at 12:18 am

    If you’re using WinForms and you want to execute something on the UI thread, you need to call either Invoke or BeginInvoke on some control (be it a Button or a Form or whatever) that was created on that thread. You’ll need a reference to it in order to do this.

    For example, with your code and assuming that you have a reference to a form called form:

    private uint lgLcdOnConfigureCB(int connection, System.IntPtr pContext)
    {
        form.Invoke(new MethodInvoker(() => OnConfigure(EventArgs.Empty)));
        return 0U;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for a long question and not a very descriptive title, but my problem
(sorry about the long title) I have a custom object Person, which in turn
Sorry for the long title, but it seems most descriptive for my question. Basically,
Sorry for the long title but couldn't think of a good way to put
Sorry for the long title. I am developing a network program in C which
Sorry for long title, the question is rather simple: I have 2 classes, Player
Sorry for the long title, but I couldn't think of another way to put
Sorry for the long question title. I guess I'm on to a loser on
I'm sorry for the long title, but I knew no other way to be
Sorry for the long title. I'm currently writing some 301 redirects and using mod

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.