Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing an endpoint inside a callback call #148

Open
alexisfouqueteuroplacer opened this issue Dec 20, 2021 · 4 comments
Open

Closing an endpoint inside a callback call #148

alexisfouqueteuroplacer opened this issue Dec 20, 2021 · 4 comments

Comments

@alexisfouqueteuroplacer
Copy link
Contributor

Hi,

Here's the situation : An application treats the received CFX messages in a callback (let say my_OnCFXMessageReceived). But at a moment, an error occurs in the callback, and we need to stop listening and let the next messages stacking in the AMQP queue. In other words, we want this callback call to be the last one before we re-open the endpoint.

Calling the Close method inside the my_OnCFXMessageReceived callback doesn't work because Close waits for my_OnCFXMessageReceived to end... Throwing an exception doesn't work either because it is caught without doing a Close.

Is there any solution to this kind of scenario?

Thanks,

Alexis

@alexisfouqueteuroplacer alexisfouqueteuroplacer changed the title Close an endpoint inside a callback call Closing an endpoint inside a callback call Dec 20, 2021
@Siox0911
Copy link
Contributor

Siox0911 commented Feb 16, 2022

If you want to close an endpoint which is running in an other context (thread). You can't do this from an other thread directly. This is thread unsafe. But you can delegate this to the UI thread. Example is for WPF.

private void Control_OnCFXMessageReceived(CFX.Transport.AmqpChannelAddress source, CFX.CFXEnvelope message)
{
    Application.Current.Dispatcher.Invoke(delegate
    {
        //Close the endpoint here
        Endpoint.Close();
    });
}

@alexisfouqueteuroplacer
Copy link
Contributor Author

Hi Siox0911. Thanks for your answer.

I understand your point, but in your example we still have the same problem, the Close() function will wait the callback to end so we are stuck... (I believe that Application.Current.Dispatcher is a synchronous call).

@Siox0911
Copy link
Contributor

Siox0911 commented Jul 25, 2022

I believe that Application.Current.Dispatcher is a synchronous call

The Invoke call just puts this on the thread responsible for the caller.

@alexisfouqueteuroplacer
Copy link
Contributor Author

Anyway in our real use case we don't have any UI, it runs as a service... But I think we should think without any specific platform or scenario. The lack I am pointing is the ability for the reception callback to request a close and avoid any new message consumption from the amqp queue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants