创建多个实例时的奇怪类行为 [英] Odd class behavior when creating multiple instances

查看:69
本文介绍了创建多个实例时的奇怪类行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-没关系...我自己处理-删除.

- Nevermind... I''ll just handle it myself - Removed.

推荐答案

我认为将委托作为参数添加到新的sub中是太多/不需要.类对象知道其所有部分,因此只需在构造函数中初始化委托.

I think putting the delegate as a parameter in the sub new is a bit much/not needed. The class object knows all of it''s parts so just initialize the delegate in the constructor.

Try
   'whatever
Catch ex As Exception
   'if you don't check the exception you won't which object is having a problem.
End Try


我们也不知道您如何使用此类.如果您调用的代码是在设置它自己的线程,则不需要它,因为此类可以为您处理所有这些事情.

的确,即使对于线程版本,这也必须是我见过最复杂的文件复制代码.
We also have no idea how your using this class. If you calling code is setting up it''s own threads, there''s no need for it because this class handles all of that for you.

Really, this has got to be the most convoluted file copy code I''ve ever seen, even for a threaded version.


类对象是处理线程操作的好方法,并且能够传递数据.这个想法是创建一个新的类对象,根据需要设置它的值,然后调用该线程将其设置为操作的线程将调用一个新线程-该类对象不必担心异步操作,因为它拥有自己的线程并在完成后自行清理所有内容.

A class object is a great way to handle a threaded operation and be able to pass data. The idea is to create the new class object set it''s values as needed then the thread calling setting this into action calls a new thread - the class object does not have to worry about async operations as it has it''s own thread and when done it cleans itself up all by itself.

Dim obj As New {your class}
obj.Filename = "some file to copy"
Dim thrd As New Thread(AddressOf obj.Worker)
thrd.IsBackground = True 'belongs to this calling process/UI
thrd.Start()


这篇关于创建多个实例时的奇怪类行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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