dbus-sharp icon indicating copy to clipboard operation
dbus-sharp copied to clipboard

Connection.GetObject blocked in signal handler

Open pwik opened this issue 8 years ago • 1 comments

Hey,

Getting an object inside a signal handler seems to block execution on the main thread when running an Iterate loop inside a separate thread. Example:

    class MyClass
    {
        Connection connection;
        SomeObject someObject;

        public MyClass()
        {
            connection = Bus.System;

            new Thread(new ThreadStart(() =>
            {
                while (connection.IsConnected)
                {
                    connection.Iterate();
                }
            })).Start();

            someObject = connection.GetObject<SomeObject>(bus_name, objpath...);

            someObject.Callback += () =>
            {
                SomeObject2 so2 = connection.GetObject<SomeObject2>(bus_name, path...);

            }
        }
    }

When the someObject.Callback handler is called the main thread stops when trying to get the SomeObject2 object. My solution to this is to create a new thread in the signal handler and from there access SomeObject2. That seems to work just fine. Am I missing something?

Running in Mono 4.6.2 on Ubuntu 16.04.

pwik avatar Feb 03 '17 15:02 pwik

Have also observed this issue and was wondering whether there is an alternative to the workaround proposed above?

anthonynovatsis avatar Apr 23 '17 10:04 anthonynovatsis