是否可以重用我的GCancellable实例?

是否可以重用我的GCancellable实例?,c,gtk3,glib,gdbus,C,Gtk3,Glib,Gdbus,在通过gdbus触发代理调用之前,我想取消这个dbus方法上任何可能的挂起调用。我的第一次尝试是这样的: // in the "member" list of my widget GCancellable *my_cancellable; // in the init method of my widget: plugin->my_cancellable = g_cancellable_new (); // in the method which does the call g_c

在通过gdbus触发代理调用之前,我想取消这个dbus方法上任何可能的挂起调用。我的第一次尝试是这样的:

// in the "member" list of my widget
GCancellable   *my_cancellable;

// in the init method of my widget:
plugin->my_cancellable = g_cancellable_new ();

// in the method which does the call
g_cancellable_cancel (plugin->my_cancellable);
my_gdbus_call_something (plugin->proxy, plugin->my_cancellable, reply_handler,plugin);
这不起作用,因为使用相同的可取消实例也将取消将来的任何调用。 看起来我无法使用,因为文档统计如下:

如果任何可取消操作当前正在使用Cancelable,则 此函数的行为未定义

是否可以检查我的GCancellable的正在使用状态?这对我有帮助吗

对我来说,已经很好用的是为每个呼叫创建一个新的可取消呼叫:

// in the "member" list of my widget
GCancellable   *my_cancellable;

// in the init method of my widget:
plugin->my_cancellable = NULL;

// in the method which does the call
if(plugin->my_cancellable != NULL)
  {
    g_cancellable_cancel (plugin->my_cancellable);
    g_object_unref (plugin->my_cancellable);
  }
plugin->my_cancellable = g_cancellable_new ();
my_gdbus_call_something (plugin->proxy, plugin->my_cancellable, reply_handler,plugin);

考虑到有一个挂起的呼叫,是否将其保存为unref my_Cancelable?这必须是一个标准用例。。我不知道是否有更好的解决方案。

我的第一次编码尝试几乎没有问题。。我只是没有意识到,当一个可取消的电话被取消时,它就不再“使用”了,所以在打电话之后,打电话是安全的

感谢JoséFonte指出这一点

这里是固定代码:

// in the "member" list of my widget
GCancellable   *my_cancellable;

// in the init method of my widget:
plugin->my_cancellable = g_cancellable_new ();

// in the method which does the call
g_cancellable_cancel (plugin->my_cancellable);
g_cancellable_reset (plugin->my_cancellable);
my_gdbus_call_something (plugin->proxy, plugin->my_cancellable, reply_handler,plugin);

您知道为什么要为
objective-c
添加标签吗?这是另一种语言,因此它似乎与我无关。那先取消它,然后重置它,然后再重新使用它怎么样?就像你说的,重置一个使用中的可取消项是未定义的,但是如果你先取消它,那么它就不在使用中,你应该能够重置它以重新使用。谢谢JoséFonte!现在似乎很好用。。我只是不知道当一个可取消文件被取消时,它就不再“使用”了。请随意用您自己的答案来完成您的问题,以“关闭”它,并作为未来读者的参考。德国劳埃德船级社