摘要: 由于线程安全问题,在多线程编程下更改一个控件的属性时,往往需要用托管来更改属性的值.下面是一个通用的托管,用反射来对属性进行赋值.public delegate void SetValueCallBack(Control control, string property, object value);public static void SetValue(Control control, string property, object value)...{ if (control.InvokeRequired) control.Invoke(new SetValueCa... 阅读全文
posted @ 2013-01-28 18:52 louiskoo 阅读(286) 评论(0) 推荐(0) 编辑
摘要: c#中禁止跨线程直接访问控件,InvokeRequired是为了解决这个问题而产生的当一个控件的InvokeRequired属性值为真时,说明有一个创建它以外的线程想访问它,此时它将会在内部调用new MethodInvoker(LoadGlobalImage)来完成下面的步骤,这个做法保证了控件的安全,你可以这样理解,有人想找你借钱,他可以直接在你的钱包中拿,这样太不安全,因此必须让别人先要告诉你,你再从自己的钱包把钱拿出来借给别人,这样就安全了在设计中为了让界面与逻辑分离,我的做法是使用事件,界面只要响应事件来处理界面的显示就行了。而事件在逻辑处理中可能由不同的线程引发,这些事件的响应方法 阅读全文
posted @ 2013-01-28 18:37 louiskoo 阅读(391) 评论(0) 推荐(0) 编辑
摘要: private delegate void AddstudyDescriptionNodeDelegate(string studyDescription, string studyUID); private void AddstudyDescriptionNode(string studyDescription, string studyUID) { if (InvokeRequired) { BeginInvoke(new AddstudyDescriptionNodeDelegate(... 阅读全文
posted @ 2013-01-28 17:02 louiskoo 阅读(182) 评论(0) 推荐(0) 编辑
摘要: public static System.Drawing.Image ByteArrayToImage(byte[] b) { ImageConverter imgconv = new ImageConverter(); System.Drawing.Image img = (System.Drawing.Image)imgconv.ConvertFrom(b); return img; } public static byte[] ImageToByteArray(System.Dra... 阅读全文
posted @ 2013-01-28 17:01 louiskoo 阅读(900) 评论(0) 推荐(0) 编辑
摘要: private void DSApictureBox_MouseDown(object sender, MouseEventArgs e) { if (drawLine) { start = new PointF(e.X,e.Y); start = LineAlgorithm.Control2Image(matrix,start); if (list1.Count == 0) { ... 阅读全文
posted @ 2013-01-28 15:34 louiskoo 阅读(13254) 评论(0) 推荐(1) 编辑
摘要: //定义委托,它定义了可以代表的方法的类型 public delegate void GreetingDelegate(string name); private static void EnglishGreeting(string name) { Console.WriteLine("Morning, " + name); } private static void ChineseGreeting(string name) { Console.WriteLine("... 阅读全文
posted @ 2013-01-28 15:12 louiskoo 阅读(1603) 评论(1) 推荐(0) 编辑