成都创新互联网站制作重庆分公司

包含vb.netwhile的词条

vb.net 等待上个命令执行完成,进行下个命令

送你一个延迟函数单位毫秒

寿阳网站建设公司创新互联,寿阳网站设计制作,有大型网站制作公司丰富经验。已为寿阳超过千家提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的寿阳做网站的公司定做!

Public Sub delay(ByRef Interval As Double)

On Error Resume Next

Dim time As DateTime = DateTime.Now

Dim Span As Double = Interval * 10000000 '因为时间是以100纳秒为单位。

While ((DateTime.Now.Ticks - time.Ticks) Span)

Application.DoEvents()

End While

End Sub

VB.NET用子线程进行大批量数据传输,UI卡死,请高手指教。代码如下

试试这个怎么样,添加在子进程里面,就加在你批量传输代码里的每一个传输后面,也就是大批量中的每传输一个数据就暂停一下,而不是每一个大批量才暂停一下

System.Threading.Thread.Sleep(10) '让它走慢一点

VB.NET 怎样编写使用Do While 循环输出1-10的阶乘,我是新手请加上文字说明,呵呵,谢谢各位了!

首先在窗体上画两个控件:TextBox1和Button1

TextBox1用来输入需要计算那个数的阶乘

双击Button1进入输入代码,代码如下

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

Dim Factorial As Integer = 1 '定义一个变量用来记录阶乘的结果

Dim count As Integer '定义一个变量用来记录需要计算那个数的阶乘

Dim i As Integer = 1 '定义一个数用来循环

count = Int(Val(Me.TextBox1.Text)) '把TextBox1的值赋值给count

Do While i = count '下面开始计算阶乘

Factorial = Factorial * i '计算阶乘

i += 1 '自增1

Loop

MessageBox.Show(Int(Val(Me.TextBox1.Text)) "的阶乘是:" Factorial, "完成", MessageBoxButtons.OK) '弹出计算结果

Catch ex As Exception '出错提示

MessageBox.Show(Err.Description, "出错了", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End Sub

vb.net中如何结束一个线程

vb.net中如何结束一个线程

一般而言,如果您想终止一个线程,您可以使用System.Threading.Thread类的Abort方法. 例如:

Dim worker As ThreadStart = New ThreadStart(AddressOf workerthreadmethod)

Dim t As Thread = New Thread(worker)

t.Start()

MessageBox.Show("Wait for a while for the thread to start.")

MessageBox.Show(t.ThreadState.ToString())

t.Abort()

MessageBox.Show(t.ThreadState.ToString())

t.Join()

MessageBox.Show(t.ThreadState.ToString())

当然,在调用Abort方法后,线程并不是立刻终止,要等线程的所有finally快中的代码完成后才会完全终止. 所以在主线程中可以用Join方法来同步,当线程还未完全终止时,t.Join()将处于等待,直到t线程完全结束后再继续执行后面的语句。

Abort方法是会导致线程跳出一个异常错误的,你需要在代码中捕获该异常。下面是一个比较完整的VB.NET线程例子:

Imports System

Imports System.Threading

Public Class MyTestApp

Public Shared Sub Main()

Dim t As New Thread(New ThreadStart(AddressOf MyThreadMethod))

'Start the thread

t.Start()

MsgBox("Are you ready to kill the thread?")

'Kill the child thread and this will cause the thread raise an exception

t.Abort()

' Wait for the thread to exit

t.Join()

MsgBox("The secondary thread has terminated.")

End Sub

Shared Sub MyThreadMethod()

Dim i As Integer

Try

Do While True

Thread.CurrentThread.Sleep(1000)

Console.WriteLine("This is the secondary thread running.")

Loop

Catch e As ThreadAbortException

MsgBox("This thread is going to be terminated by the Abort method in the Main function")

End Try

End Sub

End Class

Thread.Abort()方法用来永久销毁一个线程,而且将抛出ThreadAbortException异常。使终结的线程可以捕获到异常但是很难控制恢复,仅有的办法是调用Thread.ResetAbort()来取消刚才的调用,而且只有当这个异常是由于被调用线程引起的异常。因此,A线程可以正确的使用Thread.Abort()方法作用于B线程,但是B线程却不能调用Thread.ResetAbort()来取消Thread.Abort()操作。

vb.net 中while循环与for循环有什么不同

while为条件循环,for为计数循环。一般情况下,WHILE可替代FOR,反之则不然。


标题名称:包含vb.netwhile的词条
本文网址:http://cxhlcq.com/article/hjdjpi.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部