Vb.net Thread线程实例

Imports System.Threading

Class Class1

    'Public Shared Sub Main(ByVal args() As String)
    '    'Application.Run(New Form1())
    '    '' Get the path that stores favorite links.
    '    Shell("notepad", AppWinStyle.NormalFocus)
    'End Sub 'Main 

    Shared t As Thread
    Public Shared Sub Main()
        Console.WriteLine("Main thread: Start a second thread.")
        ' The constructor for the Thread class requires a ThreadStart
        ' delegate.  The Visual Basic AddressOf operator creates this
        ' delegate for you.
        t = New Thread(AddressOf ThreadProc1)

        ' Start ThreadProc.  Note that on a uniprocessor, the new
        ' thread does not get any processor time until the main thread
        ' is preempted or yields.  Uncomment the Thread.Sleep that
        ' follows t.Start() to see the difference.
        Console.WriteLine("ThreadState:" + CStr(t.ThreadState))
        t.Start()
        Console.WriteLine("ThreadState:" + CStr(t.ThreadState))
        Thread.Sleep(0)
        Dim i As Integer
        Console.WriteLine("Main thread:---START")
        For i = 1 To 4
            Console.WriteLine("Main thread: Do some work.")
            Threading.Thread.Sleep(0)
        Next

        Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.")
        Console.WriteLine("ThreadState:" + CStr(t.ThreadState))
        t.Join()
        Console.WriteLine("ThreadState:" + CStr(t.ThreadState))
        Console.WriteLine("Main thread: ThreadProc.Join has returned.  Press Enter to end program.")
        Console.ReadLine()
        t = New Thread(AddressOf ThreadProc2)

        ' Start ThreadProc.  Note that on a uniprocessor, the new
        ' thread does not get any processor time until the main thread
        ' is preempted or yields.  Uncomment the Thread.Sleep that
        ' follows t.Start() to see the difference.
        Console.WriteLine("ThreadState:" + CStr(t.ThreadState))
        t.Start()
        Console.WriteLine("ThreadState:" + CStr(t.ThreadState))
        t.Join()
        Console.WriteLine("ThreadState:" + CStr(t.ThreadState))
        t = New Thread(AddressOf ThreadProc3)
        t.Start()
        t.Join()
        Console.WriteLine("Main thread: ThreadProc.Join has returned.  Press Enter to end program.")
        Console.ReadLine()
    End Sub

    Public Shared Function ThreadProc1() As Integer
        Console.WriteLine("ThreadProc1---START")
        For i As Integer = 0 To 10
            Console.WriteLine(CStr(i))
        Next
        Console.WriteLine("ThreadProc1---END")
    End Function

    Public Shared Function ThreadProc2() As Integer
        Console.WriteLine("ThreadProc2---START")
        For i As Integer = 0 To 10
            Console.WriteLine(CStr(i))
        Next
        Console.WriteLine("ThreadProc2---END")
    End Function

    Public Shared Function ThreadProc3() As Integer
        Console.WriteLine("ThreadProc3---START")
        For i As Integer = 0 To 10
            Console.WriteLine(CStr(i))
        Next
        Console.WriteLine("ThreadProc3---END")
    End Function

End Class 'MyProcess


控件台输出结果:

Main thread: Start a second thread.
ThreadState:8
ThreadProc1---START
0
1
2
3
4
5
6
7
8
9
10
ThreadProc1---END
ThreadState:0
Main thread:---START
Main thread: Do some work.
Main thread: Do some work.
Main thread: Do some work.
Main thread: Do some work.
Main thread: Call Join(), to wait until ThreadProc ends.
ThreadState:16
ThreadState:16
Main thread: ThreadProc.Join has returned.  Press Enter to end program.
ThreadState:8
ThreadState:0
ThreadProc2---START
0
1
2
3
4
5
6
7
8
9
10
ThreadProc2---END
ThreadState:16
ThreadProc3---START
0
1
2
3
4
5
6
7
8
9
10
ThreadProc3---END
Main thread: ThreadProc.Join has returned.  Press Enter to end program.

 

ThreadState:8 =Unstart(没运行)

ThreadState:0=running(线程运行)

ThreadState:16=stoped (线程停止)

### 设置 Element UI `el-progress` 组件环形进度条渐变背景色 为了使 `el-progress` 的环形进度条拥有渐变背景色,可以通过自定义 CSS 和 JavaScript 来实现这一功能。具体方法如下: #### 方法一:利用内联样式与 SASS 预处理器 通过设置 `:color` 属性并结合 SASS 或其他预处理工具来创建不同状态下的颜色变化。 ```html <template> <div class="progress-container"> <el-progress type="circle" :width="70" :stroke-width="10" :color="customGradientColor" :percentage="percentValue" @click.native="handleClick"></el-progress> </div> </template> <script> export default { data() { return { percentValue: 50, customGradientColor: 'linear-gradient(90deg, rgba(255,0,0,.8), rgba(0,255,0,.8))' }; }, methods: { handleClick(event){ console.log('Progress clicked'); } } }; </script> <style lang="scss" scoped> .progress-container /deep/ .el-progress-circle__track{ stroke-dasharray: none; } .el-progress-circle__path { transition: all ease-in-out 0.3s; } /* 使用深度选择器覆盖默认样式 */ /deep/.el-progress-circle path:nth-of-type(odd) { /* 如果需要针对特定实例调整 */ } /* 对于不同的 div 应用独特的渐变色 */ .progress-item:nth-child(1) .el-progress-circle__path { stroke: linear-gradient(to right, red , yellow); } .progress-item:nth-child(2) .el-progress-circle__path { stroke: linear-gradient(to bottom, blue , green); } // ...以此类推... </style> ``` 此段代码展示了如何使用 Vue.js 结合 SASS 实现多个环形进度条的不同渐变效果[^2]。注意 `/deep/` 是用于穿透scoped样式的特殊语法,在某些版本可能已被替代为 `::v-deep` 或者直接移除以支持新的组合式 API 特性。 #### 方法二:直接操作 DOM 修改 SVG 路径填充 如果希望更灵活地控制渐变逻辑,则可以直接访问底层渲染出来的SVG元素,并对其应用CSS线性或径向渐变规则。 ```javascript mounted(){ this.$nextTick(() => { const svgPath = document.querySelector('.el-progress-circle__path'); if (svgPath) { let gradientId = "grad"; var defs = document.createElementNS("http://www.w3.org/2000/svg", "defs"); // 创建一个 LinearGradient 定义 var grad = document.createElementNS("http://www.w3.org/2000/svg","linearGradient"); grad.setAttribute("id",gradientId); // 添加两个颜色停止点 var stop1 = document.createElementNS("http://www.w3.org/2000/svg","stop"); stop1.setAttribute("offset","0%"); stop1.setAttribute("stop-color","#ffcc00"); var stop2 = document.createElementNS("http://www.w3.org/2000/svg","stop"); stop2.setAttribute("offset","100%"); stop2.setAttribute("stop-color","#ee6e73"); grad.appendChild(stop1); grad.appendChild(stop2); defs.appendChild(grad); svgPath.parentNode.insertBefore(defs, svgPath.nextSibling); svgPath.style.stroke = `url(#${gradientId})`; } }); }, ``` 这种方法绕过了框架层面的限制,允许开发者更加精细地定制视觉表现形式[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值