这个线程代码看起来不错

编程入门 行业动态 更新时间:2024-10-21 05:05:43
本文介绍了这个线程代码看起来不错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

第一次尝试线程。 这似乎挂了,我想知道它对你来说是否合适。 现在线程t只是一个表单一个取消按钮。 如果点击它会引发一个事件,在主要的 线程中将mCancelled设置为true。 - - 主线程包含 Private Sub UserCancelled(ByVal sender As Object,ByVal e As EventArgs) mCancelled = True End Sub 私人功能SetupAndPreview()As Boolean SNIP Dim mCancelled = False Dim ch As新的FormCheckForCancel ch.Show() Dim t As New Thread(AddressOf ch.AskIfCancel) t.Start() AddHandler ch.Cancelled,AddressOf UserCancelled SNIP - t线程代码是一个表格 公共类FormCheckForCancel 继承System.Windows.Forms.Form SNIP 公共事件已取消(ByVal发件人) As Object,ByVal e As EventArgs) Public Sub AskIfCancel() Do Application.DoEvents() System.Threading.Thread.Sleep(500) 循环 结束子 Private Sub ButtonCancel_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理ButtonCancel.Click RaiseEvent取消(我,没什么) Me.Close() End Sub 结束班

解决方案

第一件事跳出来的是变量m_Cancelled。你在一个函数中暗淡了它的b $ b,但是尝试在另一个子函数中更改它的值。你可能想要在你的子程序和函数之外声明它,所以它可以是 所有东西都可以访问。 "只是我 < GR **** @ a-znet>在消息中写道 news:u1 ************** @ TK2MSFTNGP12.phx.gbl ...

尝试第一个线程时间。这似乎挂了,我想知道它对你来说是否合适。现在线程t只是一个带有取消按钮的表格。如果点击它会引发一个事件,在主线程中将mCancelled设置为true。 ---主线程包含 Private Sub UserCancelled(ByVal sender As Object,ByVal e As EventArgs) mCancelled = True End Sub 私人函数SetupAndPreview()As Boolean SNIP Dim mCancelled = False Dim ch As New FormCheckForCancel ch.Show() Dim t As New Thread(AddressOf ch.AskIfCancel) t.Start() AddHandler ch.Cancelled,AddressOf UserCancelled SNIP - t线程代码是一个表格公共类FormCheckForCancel 继承System.Windows.Forms.Form SNIP 公共事件取消(ByVal发送者作为对象,ByVal e作为EventArgs) 公共子AskIfCancel()做 Application.DoEvents() System.Threading.Thread.Sleep (500)循环 私有子ButtonCancel_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理ButtonCancel.Click RaiseEvent取消(我,没什么) Me.Close() End Sub End Class

对不起,我试图缩短代码并引入了一个bug。我有: 朋友mCancelled As Boolean 使用表单作为主题是否正确? 谢谢 " OpticTygre" <运算******** @ adelphia>在消息中写道 新闻:sZ ******************** @ adelphia ...

跳出来的第一件事是变量m_Cancelled。你在一个函数中暗淡它,但尝试在另一个子函数中更改它的值。您可能希望在子程序和函数之外声明它,以便所有内容都可以访问它。 "只是我 < GR **** @ a-znet>在消息中写道新闻:u1 ************** @ TK2MSFTNGP12.phx.gbl ...

第一次尝试线程。这似乎挂了,我想知道它对你来说是否合适。现在线程t只是一个带有取消按钮的表单。如果点击它会引发一个将mCancelled设置为true的事件在主线程中。 ---主线程包含 Private Sub UserCancelled(ByVal sender As Object,ByVal e As EventArgs) mCancelled = True <结束子 私人函数SetupAndPreview()As Boolean SNIP Dim mCancelled = False Dim ch As New FormCheckForCancel ch.Show( ) Dim t As New Thread(AddressOf ch.AskIfCancel) t.Start() AddHandler ch.Cancelled,AddressOf UserCancelled SNIP - -T线程代码是一个表格公共类FormCheckForCancel 继承System.Windows.Forms.Form SNIP 公共事件取消lled(ByVal sender As Object,ByVal e As EventArgs) Public Sub AskIfCancel()做 Application.DoEvents() System.Threading.Thread.Sleep (500)循环 私有子ButtonCancel_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理ButtonCancel.Click RaiseEvent取消(我,没什么) Me.Close() End Sub End Class

"只是我 < GR **** @ a-znet>在消息中写道 news:ea *************** @ TK2MSFTNGP15.phx.gbl ...

我是对不起,我试图简化代码并引入了一个错误。我有:朋友mCancelled As Boolean 并且没有Dim on mCancelled = False 我将其删除下面是否真的使用了一个Form for the thread好的? 谢谢 OpticTygre <运算******** @ adelphia>在消息中写道新闻:sZ ******************** @ adelphia ...

跳跃的第一件事在我身边是变量m_Cancelled。你在一个函数中调暗它,但是尝试在另一个子函数中改变它的值。你可能想要在子例程和函数之外声明它,以便它可以被所有东西访问。 "只是我 < GR **** @ a-znet>在消息中写道新闻:u1 ************** @ TK2MSFTNGP12.phx.gbl ...

第一次尝试线程。这似乎挂了,我想知道它对你来说是否合适。现在线程t只是一个带有取消按钮的表单。如果点击它会引发一个将mCancelled设置为true的事件在主线程中。 ---主线程包含 Private Sub UserCancelled(ByVal sender As Object,ByVal e As EventArgs) mCancelled = True <结束子 私有函数SetupAndPreview()As Boolean SNIP mCancelled = False Dim ch As New FormCheckForCancel ch.Show() Dim t As New Thread(AddressOf ch.AskIfCancel) t.Start() AddHandler ch.Cancelled,AddressOf UserCancelled SNIP - t线程代码是一个表格公共类FormCheckForCancel 继承System.Windows.Forms.Form SNIP 公共事件已取消(ByVal sender As Object,ByVal e As EventArgs) Public Sub AskIfCancel()做Application.DoEvents() System.Threading.Thread.Sleep( 500)循环 私有子ButtonCancel_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理ButtonCancel.Click <取消了RaiseEvent(我,没什么) Me.Close() End Sub End Class

Trying threads for the first time. This seems to hang and I wonder if it looks OK to you. Right now the thread t is simply a Form with a Cancel Button. If clicked it should raise an event that sets mCancelled to true in the main thread. ---The main thread contains Private Sub UserCancelled(ByVal sender As Object, ByVal e As EventArgs) mCancelled = True End Sub Private Function SetupAndPreview() As Boolean SNIP Dim mCancelled = False Dim ch As New FormCheckForCancel ch.Show() Dim t As New Thread(AddressOf ch.AskIfCancel) t.Start() AddHandler ch.Cancelled, AddressOf UserCancelled SNIP --The t thread code is a Form Public Class FormCheckForCancel Inherits System.Windows.Forms.Form SNIP Public Event Cancelled(ByVal sender As Object, ByVal e As EventArgs) Public Sub AskIfCancel() Do Application.DoEvents() System.Threading.Thread.Sleep(500) Loop End Sub Private Sub ButtonCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonCancel.Click RaiseEvent Cancelled(Me, Nothing) Me.Close() End Sub End Class

解决方案

The first thing that jumps out at me is the variable m_Cancelled. You Dim it in one function, but try to change the value of it in another sub. You may want to declare it outside your subroutines and functions so it can be accessible to everything. " Just Me" <gr****@a-znet> wrote in message news:u1**************@TK2MSFTNGP12.phx.gbl...

Trying threads for the first time. This seems to hang and I wonder if it looks OK to you. Right now the thread t is simply a Form with a Cancel Button. If clicked it should raise an event that sets mCancelled to true in the main thread. ---The main thread contains Private Sub UserCancelled(ByVal sender As Object, ByVal e As EventArgs) mCancelled = True End Sub Private Function SetupAndPreview() As Boolean SNIP Dim mCancelled = False Dim ch As New FormCheckForCancel ch.Show() Dim t As New Thread(AddressOf ch.AskIfCancel) t.Start() AddHandler ch.Cancelled, AddressOf UserCancelled SNIP --The t thread code is a Form Public Class FormCheckForCancel Inherits System.Windows.Forms.Form SNIP Public Event Cancelled(ByVal sender As Object, ByVal e As EventArgs) Public Sub AskIfCancel() Do Application.DoEvents() System.Threading.Thread.Sleep(500) Loop End Sub Private Sub ButtonCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonCancel.Click RaiseEvent Cancelled(Me, Nothing) Me.Close() End Sub End Class

I''m sorry, I tried to make the code short and introduced a bug. I do have: Friend mCancelled As Boolean Is it true that using a Form for the thread is OK? Thanks "OpticTygre" <op********@adelphia> wrote in message news:sZ********************@adelphia...

The first thing that jumps out at me is the variable m_Cancelled. You Dim it in one function, but try to change the value of it in another sub. You may want to declare it outside your subroutines and functions so it can be accessible to everything. " Just Me" <gr****@a-znet> wrote in message news:u1**************@TK2MSFTNGP12.phx.gbl...

Trying threads for the first time. This seems to hang and I wonder if it looks OK to you. Right now the thread t is simply a Form with a Cancel Button. If clicked it should raise an event that sets mCancelled to true in the main thread. ---The main thread contains Private Sub UserCancelled(ByVal sender As Object, ByVal e As EventArgs) mCancelled = True End Sub Private Function SetupAndPreview() As Boolean SNIP Dim mCancelled = False Dim ch As New FormCheckForCancel ch.Show() Dim t As New Thread(AddressOf ch.AskIfCancel) t.Start() AddHandler ch.Cancelled, AddressOf UserCancelled SNIP --The t thread code is a Form Public Class FormCheckForCancel Inherits System.Windows.Forms.Form SNIP Public Event Cancelled(ByVal sender As Object, ByVal e As EventArgs) Public Sub AskIfCancel() Do Application.DoEvents() System.Threading.Thread.Sleep(500) Loop End Sub Private Sub ButtonCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonCancel.Click RaiseEvent Cancelled(Me, Nothing) Me.Close() End Sub End Class

" Just Me" <gr****@a-znet> wrote in message news:ea***************@TK2MSFTNGP15.phx.gbl...

I''m sorry, I tried to make the code short and introduced a bug. I do have: Friend mCancelled As Boolean and no Dim on mCancelled = False I removed it below Is it true that using a Form for the thread is OK? Thanks "OpticTygre" <op********@adelphia> wrote in message news:sZ********************@adelphia...

The first thing that jumps out at me is the variable m_Cancelled. You Dim it in one function, but try to change the value of it in another sub. You may want to declare it outside your subroutines and functions so it can be accessible to everything. " Just Me" <gr****@a-znet> wrote in message news:u1**************@TK2MSFTNGP12.phx.gbl...

Trying threads for the first time. This seems to hang and I wonder if it looks OK to you. Right now the thread t is simply a Form with a Cancel Button. If clicked it should raise an event that sets mCancelled to true in the main thread. ---The main thread contains Private Sub UserCancelled(ByVal sender As Object, ByVal e As EventArgs) mCancelled = True End Sub Private Function SetupAndPreview() As Boolean SNIP mCancelled = False Dim ch As New FormCheckForCancel ch.Show() Dim t As New Thread(AddressOf ch.AskIfCancel) t.Start() AddHandler ch.Cancelled, AddressOf UserCancelled SNIP --The t thread code is a Form Public Class FormCheckForCancel Inherits System.Windows.Forms.Form SNIP Public Event Cancelled(ByVal sender As Object, ByVal e As EventArgs) Public Sub AskIfCancel() Do Application.DoEvents() System.Threading.Thread.Sleep(500) Loop End Sub Private Sub ButtonCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonCancel.Click RaiseEvent Cancelled(Me, Nothing) Me.Close() End Sub End Class

更多推荐

这个线程代码看起来不错

本文发布于:2023-11-13 00:43:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582941.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!