惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
博客园 - 司徒正美
Last Week in AI
Last Week in AI
博客园 - 聂微东
Jina AI
Jina AI
月光博客
月光博客
爱范儿
爱范儿
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
T
Tailwind CSS Blog
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
罗磊的独立博客
小众软件
小众软件
雷峰网
雷峰网
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog

博客园 - 哑吧湖大水怪

MAF框架架构设计概览 rabbitmq 相关概念 使用AutoMapper时Expression的转换 unity 三种注入示例 DNS解析过程详解 手工设置Windows服务依赖关系 .NET Micro Framework简介 .net MF 学习 数码管显示 .NET MF固件部署 LED灯控制 Hello World 你懂的 .NET MF环境的安装 str to date C#实现在WinForm窗口标题栏上添加按钮 摄像头操作(转) 获取客户端相关信息 任务栏的显示与隐藏 winfrom 特效 [转载]
线程间操作控件
哑吧湖大水怪 · 2011-03-16 · via 博客园 - 哑吧湖大水怪

delegate void bindvalue(object Instance, string Property, object value);
delegate object invokemethod(object Instance, string Method, object[] parameters);
delegate object invokepmethod(object Instance, string Property, string Method, object[] parameters);
delegate object invokechailmethod(object InstanceInvokeRequired, object Instance, string Method, object[] parameters);/// <summary>
/// 委托设置对象属性
/// </summary>
/// <param name="Instance">对象</param>
/// <param name="Property">属性名</param>
/// <param name="value">属性值</param>
private void SetValue(object Instance, string Property, object value)
{
if ((bool)GetPropertyValue(Instance, "InvokeRequired"))
{
bindvalue d
= new bindvalue(SetValue);
this.Invoke(d, new object[] { Instance, Property, value });
}
else
{
SetPropertyValue(Instance, Property, value);
}
}
/// <summary>
/// 委托执行实例的方法
/// </summary>
/// <param name="Instance">类实例</param>
/// <param name="Method">方法名</param>
/// <param name="parameters">参数列表</param>
/// <returns>返回值</returns>
private object InvokeMethod(object Instance, string Method, object[] parameters)
{
if ((bool)GetPropertyValue(Instance, "InvokeRequired"))
{
invokemethod d
= new invokemethod(InvokeMethod);
return this.Invoke(d, new object[] { Instance, Method, parameters });
}
else
{
return MethodInvoke(Instance, Method, parameters);
}
}
/// <summary>
/// 委托执行实例的方法
/// </summary>
/// <param name="InstanceInvokeRequired">窗体控件对象</param>
/// <param name="Instance">需要执行方法的对象</param>
/// <param name="Method">方法名</param>
/// <param name="parameters">参数列表</param>
/// <returns>返回值</returns>
private object InvokeChailMethod(object InstanceInvokeRequired, object Instance, string Method, object[] parameters)
{
if ((bool)GetPropertyValue(InstanceInvokeRequired, "InvokeRequired"))
{
invokechailmethod d
= new invokechailmethod(InvokeChailMethod);
return this.Invoke(d, new object[] { InstanceInvokeRequired, Instance, Method, parameters });
}
else
{
return MethodInvoke(Instance, Method, parameters);
}
}
/// <summary>
/// 委托执行实例的属性的方法
/// </summary>
/// <param name="Instance">类实例</param>
/// <param name="Property">属性名</param>
/// <param name="Method">方法名</param>
/// <param name="parameters">参数列表</param>
/// <returns>返回值</returns>
private object InvokePMethod(object Instance, string Property, string Method, object[] parameters)
{
if ((bool)GetPropertyValue(Instance, "InvokeRequired"))
{
invokepmethod d
= new invokepmethod(InvokePMethod);
return this.Invoke(d, new object[] { Instance, Property, Method, parameters });
}
else
{
return MethodInvoke(GetPropertyValue(Instance, Property), Method, parameters);
}
}
/// <summary>
/// 获取实例的属性值
/// </summary>
/// <param name="ClassInstance">类实例</param>
/// <param name="PropertyName">属性名</param>
/// <returns>属性值</returns>
private static object GetPropertyValue(object ClassInstance, string PropertyName)
{
Type myType
= ClassInstance.GetType();
PropertyInfo myPropertyInfo
= myType.GetProperty(PropertyName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
return myPropertyInfo.GetValue(ClassInstance, null);
}
/// <summary>
/// 设置实例的属性值
/// </summary>
/// <param name="ClassInstance">类实例</param>
/// <param name="PropertyName">属性名</param>
private static void SetPropertyValue(object ClassInstance, string PropertyName, object PropertyValue)
{
Type myType
= ClassInstance.GetType();
PropertyInfo myPropertyInfo
= myType.GetProperty(PropertyName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
myPropertyInfo.SetValue(ClassInstance, PropertyValue,
null);
}
/// <summary>
/// 执行实例的方法
/// </summary>
/// <param name="ClassInstance">类实例</param>
/// <param name="MethodName">方法名</param>
/// <param name="parameters">参数列表</param>
/// <returns>返回值</returns>
private static object MethodInvoke(object ClassInstance, string MethodName, object[] parameters)
{
if (parameters == null)
{
parameters
= new object[0];
}
Type myType
= ClassInstance.GetType();
Type[] types
= new Type[parameters.Length];
for (int i = 0; i < parameters.Length; ++i)
{
types[i]
= parameters[i].GetType();
}
MethodInfo myMethodInfo
= myType.GetMethod(MethodName, types);
return myMethodInfo.Invoke(ClassInstance, parameters);
}