继承线程类 [英] inherits thread class
问题描述
我是vb.net的新手,只是为了感受它而感觉好b / b
。我来自一个vb6 / java背景所以请
如果我的想法很简单或者很好,那么请不要这么做。
dot net中的编程练习。在java中,一个类可以实现runnable
,然后run方法作为一个新的线程启动。我想尝试在
vb.net中做同样的事情但是很难找到任何关于做这样的事情的例子。我知道我可以在课堂上产生一个正常的线程,但我只是想(更危险的是我通常告诉:-)
)关于更优雅的解决方案。 />
问候,
Michael
I am new to vb.net and just playing around to get a feel
for it. I am coming from a vb6/java background so please
excuse me if my idea is plain stupid or contra good
programming practice in dot net. In java a class can
implement runnable and then the run method is started as a
new thread. I want to attempt to do the same thing in
vb.net but have struggled to find any examples about doing
anything like this. I know I could spawn a thread as
normal in a class but was just thinking ( dangerous I am
usually told :-) ) about a more elegant solution.
Regards,
Michael
推荐答案
我不认为继承是合适的。只需使用Threading
命名空间(并创建一个导入它的类)。如果你想要以某种显着的方式扩展Threading类(命名空间),你会继承。
你想要做的就是使用免费的线程。 IMO,继承增加
除了这种情况的复杂性之外没什么。
迪克
-
Richard Grier(微软Visual Basic MVP)
见 www.hardandsoftware.net 获取联系信息。
Visual Basic程序员串行通信指南的作者,第3版
版ISBN 1-890422-27-4(391页)2002年2月出版。
Hi,
I don''t think inheritance is appropriate. Simply use the Threading
namespace (and create a class that imports it). You would inherit if you
wanted to extend the Threading class (namespace) in some significant way.
All that you want to do is to employ free threading. IMO, inheritance adds
nothing except complexity to this scenario.
Dick
--
Richard Grier (Microsoft Visual Basic MVP)
See www.hardandsoftware.net for contact information.
Author of Visual Basic Programmer''s Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
嗨迈克尔,
不知道Java,什么'runnable接口和run()做什么?
我知道异步代理可能对你有用,但我是
不确定。
问候,
Fergus
Hi Michael,
Not knowing Java, what''s the runnable interface and what does run() do?
I''ve an idea that asynchronous Delegates might be useful to you, but I''m
not sure.
Regards,
Fergus
我只是进入线程并且已经有点挣扎,但是在这样做的过程中,我找到了一些我认为可能对你有帮助的东西。我想你需要做的是创建一个抽象(MustInherit)类,
完成创建新线程的所有基本内容,并允许你轮询
线程是否完整。我不能相信它,它来自
Francesco Balena的书编程Microsoft Visual Basic .NET,但是我想b / b
无论如何你。下面是Balena的代码
ThreadWrapperBase类:
公共MustInherit类ThreadWrapperBase
私有m_Done为布尔
Public ReadOnly Thread As System.Threading.Thread
Sub New()
Me.Thread = New System.Threading.Thread(AddressOf Me.RunThread)
End Sub
Public Overridable Sub Start()
Me.Thread.Start()
结束子
私有子RunThread()
m_Done =错误
OnStart()
m_Done =真
结束子
Public ReadOnly Property Done()As Boolean
获取
返回m_Done
结束获取
结束财产
受保护的MustOverride Sub OnStart()
结束课程
我们的想法是你可以通过覆盖OnStart
proc的类来推导它edure,这种简化了整个过程。无论如何,希望它
帮助。
迈克
-
迈克尔Caputo
程序员/数据库管理员
Simon Economic Systems Ltd.
847-272-7691
mi ************ @ radarwire.com
迈克尔 < MI ********** @ hotmail.spam>在消息中写道
news:0a **************************** @ phx.gbl ...
我是vb.net的新手,只是为了感受它而感觉好b / b
。我来自一个vb6 / java背景所以请
如果我的想法很简单或者很好,那么请不要这么做。
dot net中的编程练习。在java中,一个类可以实现runnable
,然后run方法作为一个新的线程启动。我想尝试在
vb.net中做同样的事情但是很难找到任何关于做这样的事情的例子。我知道我可以在课堂上产生一个正常的线程,但我只是想(更危险的是我通常告诉:-)
)关于更优雅的解决方案。 />
问候,
Michael
I''m just getting going on threading and have struggled a bit with it, but in
the course of doing so, I found something that I think might help you. I
think what you need to do is create an abstract (MustInherit) class that
does all the basic stuff for creating a new thread and allowing you to poll
whether the thread is complete. I can''t take credit for it, it''s from
Francesco Balena''s book Programming Microsoft Visual Basic .NET, but I
figured it might help you anyway. Here is the code for Balena''s
ThreadWrapperBase class:
Public MustInherit Class ThreadWrapperBase
Private m_Done As Boolean
Public ReadOnly Thread As System.Threading.Thread
Sub New()
Me.Thread = New System.Threading.Thread(AddressOf Me.RunThread)
End Sub
Public Overridable Sub Start()
Me.Thread.Start()
End Sub
Private Sub RunThread()
m_Done = False
OnStart()
m_Done = True
End Sub
Public ReadOnly Property Done() As Boolean
Get
Return m_Done
End Get
End Property
Protected MustOverride Sub OnStart()
End Class
The idea is you can derive from it with classes that override the OnStart
procedure, which kind of simplifies the whole process. Anyway, hope it
helps.
Mike
--
Michael Caputo
Programmer/Database Administrator
Simon Economic Systems Ltd.
847-272-7691
mi************@radarwire.com
"Michael" <mi**********@hotmail.spam> wrote in message
news:0a****************************@phx.gbl...
I am new to vb.net and just playing around to get a feel
for it. I am coming from a vb6/java background so please
excuse me if my idea is plain stupid or contra good
programming practice in dot net. In java a class can
implement runnable and then the run method is started as a
new thread. I want to attempt to do the same thing in
vb.net but have struggled to find any examples about doing
anything like this. I know I could spawn a thread as
normal in a class but was just thinking ( dangerous I am
usually told :-) ) about a more elegant solution.
Regards,
Michael
这篇关于继承线程类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!