Gtk.RecentManager:列出项目的方法

时间:2009-10-11 11:42:36

标签: mono gtk#

我想列出所有“最近使用过的”商品。 我使用这段代码:

public static void Main(string[] args)
{
    Application.Init ();
    RecentManager rm = RecentManager.Default;
    GLib.List items = rm.Items;
    Console.WriteLine(items.Count+" items.");
    foreach(object item in items)
    {
        Console.WriteLine(item.ToString());
    }           
    Console.WriteLine("Done.");
    Console.ReadKey();
}

如果Items-list为空,则按预期工作。但是,如果RecentManager确实包含Items,我将得到:

3 items.
Stacktrace:

  at (wrapper managed-to-native) GLib.Object.gtksharp_is_object (intptr) <0x00070>
  at (wrapper managed-to-native) GLib.Object.gtksharp_is_object (intptr) <0xffffffff>
  at GLib.Object.IsObject (intptr) <0x00013>
  at GLib.ListBase.DataMarshal (intptr) <0x003ff>
  at GLib.ListBase/ListEnumerator.get_Current () <0x0004b>
  at ruCmd.MainClass.Main (string[]) [0x00038] in /home/nils/Projekte/RecentlyUsed/ruCmd/Main.cs:14
  at (wrapper runtime-invoke) ruCmd.MainClass.runtime_invoke_void_object (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

    /usr/bin/mono [0x480c90]
    /usr/bin/mono [0x4b004d]
    /lib/libpthread.so.0 [0x7fad5b7c85a0]
    /usr/lib/libgobject-2.0.so.0(g_type_check_instance_is_a+0x53) [0x7fad55c642e3]
    [0x41d48b00]

=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

我处理Gtk#/ GLib时是否有错误? 我已经重建了我的单一环境。

1 个答案:

答案 0 :(得分:0)

Gtk-sharp邮件列表helped out
这是known bug,但存在变通方法。以下代码有效:

public static void Main(string[] args)
{
    Application.Init ();
    RecentManager rm = RecentManager.Default;
    GLib.List items = new GLib.List(rm.Items.Handle, typeof(RecentInfo), true, true);
    Console.WriteLine(items.Count+" items.");
    foreach(RecentInfo item in items)
    {
        Console.WriteLine(item.DisplayName);
    }           
    Console.WriteLine("Done.");
    Console.ReadKey();
}