跨进程将在WinForms的C#自定义对象类型的降 [英] Cross-Process Drag and Drop of custom object type in WinForms C#

查看:208
本文介绍了跨进程将在WinForms的C#自定义对象类型的降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是接近我很感兴趣,但并不完全。

This question is close to what I'm interested in, but not quite.

我在C#编写的.NET WinForms应用程序。我有一个显示C#对象的数组ListView控件。我已经迷上它,这样你可以拖动/删除这些列表视图项目在同一应用程序不同的形式,并通过适当的对象(类型为会议),以用于其他形式的下拉处理的数组。

I have a .NET WinForms application written in C#. I have a ListView control which displays an array of C# objects. I've hooked it up so that you can drag/drop these listview items to a different form in the same application, and it properly passes the array of objects (type "Session") to the Drop handler for that other form.

不过,我现在要支持跨进程拖/放,我跑我的应用程序的多个实例。这的出现的,它的去上班(如GetDataPresent成功),但最终抛出一个异常,当我真正尝试检索数据 - 不能施放对象[]以会议[]。

However, I now want to support cross-process drag/drop where I run multiple instances of my application. This appears that it's going to work (e.g. GetDataPresent succeeds), but ultimately throws an exception when I actually try to retrieve the data-- cannot cast object[] to Session[].

if (e.Data.GetDataPresent("Fiddler.Session[]"))
{
   Session[] oDroppedSessions;
   try
   {
      oDroppedSessions = (Session[])e.Data.GetData("Fiddler.Session[]");
   }
   catch (Exception eX)
   {  // reaches here 
   }
}

任何人都知道,如果我的必须为了使这项工作实现了ISerializable我的对象?通常情况下,我想简单的尝试,但实现了ISerializable这个类将是非常不平凡的,我很担心,可能会有这样奇怪的副作用。

Anyone know if I must implement ISerializable for my objects in order to make this work? Ordinarily, I'd simply try it, but implementing ISerializable for this class would be quite non-trivial, and I'm worried that there may be weird side-effects of doing so.

更新:实现ISerializable的不帮助 - 该方法不会被调用。同样,添加Serializable属性的类具有完全没有影响。任何其他的想法?

UPDATE: Implementing ISerializable doesn't help-- the method is never called. Similarly, adding the Serializable attribute to the class has no impact at all. Any other ideas?

感谢您的指点!

推荐答案

您正在穿越一个过程边界,对象引用不是在另一个进程中有效。 DataObject类支持序列化对象在墙上,让他们,它使用的BinaryFormatter。所以,是的,你需要到[Serializable]属性应用到你的类,并确保你的对象可以取消/序列正常。

You are crossing a process boundary, object references are not valid in another process. The DataObject class supports serializing objects to get them across the wall, it uses BinaryFormatter. So, yes, you'll need to apply the [Serializable] attribute to your class and make sure your objects can de/serialize properly.

这篇关于跨进程将在WinForms的C#自定义对象类型的降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆