Skip to content
This repository was archived by the owner on Nov 29, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Plain Craft Launcher 2/Controls/MyImage.vb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
ActualSource = TempPath
If (Date.Now - TempFile.LastWriteTime) < FileCacheExpiredTime Then Exit Sub '无需刷新缓存
End If
RunInNewThread(
RunInNewTask(
Sub()
Dim TempDownloadingPath As String = Nothing
Try
Expand Down
2 changes: 1 addition & 1 deletion Plain Craft Launcher 2/Controls/MyResizer.vb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Public Class MyResizer
If rightElements.ContainsKey(key) Then resizeRight = True
If upElements.ContainsKey(key) Then resizeUp = True
If downElements.ContainsKey(key) Then resizeDown = True
RunInNewThread(AddressOf updateSizeLoop, "窗口大小调整检测")
RunInNewTask(AddressOf updateSizeLoop, "窗口大小调整检测")
End Sub

Private Sub updateSizeLoop()
Expand Down
4 changes: 2 additions & 2 deletions Plain Craft Launcher 2/Controls/MyTextBox.vb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
If IsLoaded AndAlso labWrong IsNot Nothing Then
ChangeValidateResult(IsValidated, True)
Else
RunInNewThread(
RunInNewTask(
Sub()
Thread.Sleep(30)
RunInUi(Sub() ChangeValidateResult(IsValidated, False))
Expand All @@ -126,7 +126,7 @@
If IsLoaded AndAlso labWrong IsNot Nothing Then
labWrong.Text = ValidateResult
Else
RunInNewThread(
RunInNewTask(
Sub()
Dim IsFinished As Boolean = False
Do Until IsFinished
Expand Down
10 changes: 5 additions & 5 deletions Plain Craft Launcher 2/FormMain.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Public Class FormMain
End If
Dim Content As String = "· " & Join(ContentList, vbCrLf & "· ")
'输出更新日志
RunInNewThread(
RunInNewTask(
Sub()
If MyMsgBox(Content, "PCL 已更新至 " & VersionDisplayName, "确定", "完整更新日志") = 2 Then
OpenWebsite("https://afdian.com/a/LTCat?tab=feed")
Expand Down Expand Up @@ -296,7 +296,7 @@ Public Class FormMain
AniStart()
TimerMainStart()
'加载池
RunInNewThread(
RunInNewTask(
Sub()
'EULA 提示
If Not Setup.Get("SystemEula") Then
Expand All @@ -315,7 +315,7 @@ Public Class FormMain
DlClientListMojangLoader.Start(1)
RunCountSub()
ServerLoader.Start(1)
RunInNewThread(AddressOf TryClearTaskTemp, "TryClearTaskTemp", ThreadPriority.BelowNormal)
RunInNewTask(AddressOf TryClearTaskTemp, "TryClearTaskTemp", ThreadPriority.BelowNormal)
Catch ex As Exception
Log(ex, "初始化加载池运行失败", LogLevel.Feedback)
End Try
Expand Down Expand Up @@ -448,7 +448,7 @@ Public Class FormMain
If SendWarning AndAlso HasDownloadingTask() Then
If MyMsgBox("还有下载任务尚未完成,是否确定退出?", "提示", "确定", "取消") = 1 Then
'强行结束下载任务
RunInNewThread(
RunInNewTask(
Sub()
Log("[System] 正在强行停止任务")
For Each Task As LoaderBase In LoaderTaskbar.ToList()
Expand Down Expand Up @@ -721,7 +721,7 @@ Public Class FormMain
End Try
End Sub
Private Sub FileDrag(FilePathList As IEnumerable(Of String))
RunInNewThread(
RunInNewTask(
Sub()
Dim FilePath As String = FilePathList.First
Log("[System] 接受文件拖拽:" & FilePath & If(FilePathList.Any, $" 等 {FilePathList.Count} 个文件", ""), LogLevel.Developer)
Expand Down
2 changes: 1 addition & 1 deletion Plain Craft Launcher 2/Modules/Base/ModAnimation.vb
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ Public Module ModAnimation
AniFPSTimer = AniLastTick
AniRunning = True '标记动画执行开始

RunInNewThread(Sub()
RunInNewTask(Sub()
Try
Log("[Animation] 动画线程开始")
Do While True
Expand Down
21 changes: 12 additions & 9 deletions Plain Craft Launcher 2/Modules/Base/ModBase.vb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Imports System.Runtime.CompilerServices
Imports System.Security.Cryptography
Imports System.Security.Principal
Imports System.Text.RegularExpressions
Imports System.Threading.Tasks
Imports System.Xaml
Imports Newtonsoft.Json

Expand Down Expand Up @@ -2401,19 +2402,21 @@ NextElement:
''' <summary>
''' 在新的工作线程中执行代码。
''' </summary>
Public Function RunInNewThread(Action As Action, Optional Name As String = Nothing, Optional Priority As ThreadPriority = ThreadPriority.Normal) As Thread
Dim th As New Thread(
Public Function RunInNewTask(Action As Action, Optional Name As String = Nothing, Optional Priority As ThreadPriority = ThreadPriority.Normal, Optional Token As CancellationToken? = Nothing) As Task
If Token Is Nothing Then Token = CancellationToken.None
' If Priority <> ThreadPriority.Normal Then Throw New Exception("Task 没有优先级,不准用")
Dim task As New Task(
Sub()
Try
Action()
Catch ex As ThreadInterruptedException
Log(Name & ":线程已中止")
Log(Name & ":Task 已中止")
Catch ex As Exception
Log(ex, Name & ":线程执行失败", LogLevel.Feedback)
Log(ex, Name & ":Task 执行失败", LogLevel.Feedback)
End Try
End Sub) With {.Name = If(Name, "Runtime New Invoke " & GetUuid() & "#"), .Priority = Priority}
th.Start()
Return th
End Sub, Token)
task.Start()
Return task
End Function
''' <summary>
''' 确保在 UI 线程中执行代码。
Expand Down Expand Up @@ -2457,7 +2460,7 @@ NextElement:
''' </summary>
Public Sub RunInThread(Action As Action)
If RunInUi() Then
RunInNewThread(Action, "Runtime Invoke " & GetUuid() & "#")
RunInNewTask(Action, "Runtime Invoke " & GetUuid() & "#")
Else
Action()
End If
Expand Down Expand Up @@ -2851,7 +2854,7 @@ Retry:
Private LogList As New StringBuilder
Private LogWritter As StreamWriter
Public Sub LogStart()
RunInNewThread(
RunInNewTask(
Sub()
Dim IsInitSuccess As Boolean = True
Try
Expand Down
2 changes: 1 addition & 1 deletion Plain Craft Launcher 2/Modules/Base/ModLoader.vb
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@
State = LoadState.Failed
End Try
End Sub) With {.Name = Name, .Priority = ThreadPriority}
LastRunningThread.Start() '不能使用 RunInNewThread,否则在函数返回前线程就会运行完,导致误判 IsAborted
LastRunningThread.Start() '不能使用 RunInNewTask,否则在函数返回前线程就会运行完,导致误判 IsAborted
End Sub
Public Overrides Sub Abort()
If State <> LoadState.Loading Then Exit Sub
Expand Down
12 changes: 6 additions & 6 deletions Plain Craft Launcher 2/Modules/Base/ModNet.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ NextElement:
End SyncLock
State = LoadState.Loading
'开始执行
RunInNewThread(
RunInNewTask(
Sub()
Try
'输入检测
Expand Down Expand Up @@ -1641,14 +1641,14 @@ NextElement:
If FilesInThread.Count = FilesPerThread Then
Dim FilesToRun As New List(Of NetFile)
FilesToRun.AddRange(FilesInThread)
RunInNewThread(Sub() StartCopy(FilesToRun, FoldersFinal), "NetTask FileCopy " & Uuid)
RunInNewTask(Sub() StartCopy(FilesToRun, FoldersFinal), "NetTask FileCopy " & Uuid)
FilesInThread.Clear()
End If
Next
If FilesInThread.Any Then
Dim FilesToRun As New List(Of NetFile)
FilesToRun.AddRange(FilesInThread)
RunInNewThread(Sub() StartCopy(FilesToRun, FoldersFinal), "NetTask FileCopy " & Uuid)
RunInNewTask(Sub() StartCopy(FilesToRun, FoldersFinal), "NetTask FileCopy " & Uuid)
FilesInThread.Clear()
End If
Catch ex As Exception
Expand Down Expand Up @@ -1939,9 +1939,9 @@ Retry:
Log(ex, $"下载管理启动线程 {Id} 出错", LogLevel.Assert)
End Try
End Sub
RunInNewThread(Sub() ThreadStarter(0), "NetManager ThreadStarter 0")
RunInNewThread(Sub() ThreadStarter(1), "NetManager ThreadStarter 1")
RunInNewThread(
RunInNewTask(Sub() ThreadStarter(0), "NetManager ThreadStarter 0")
RunInNewTask(Sub() ThreadStarter(1), "NetManager ThreadStarter 1")
RunInNewTask(
Sub()
Try
Dim LastLoopTime As Long
Expand Down
24 changes: 13 additions & 11 deletions Plain Craft Launcher 2/Modules/Minecraft/ModComp.vb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Public Module ModComp
Imports System.Threading.Tasks

Public Module ModComp

Public Enum CompType
''' <summary>
Expand Down Expand Up @@ -959,17 +961,18 @@ Retry:

#Region "从 CurseForge 和 Modrinth 获取结果列表,存储于 RawResults"

Dim CurseForgeThread As Thread = Nothing
Dim ModrinthThread As Thread = Nothing
Dim CurseForgeThread As Task = Nothing
Dim ModrinthThread As Task = Nothing
Dim ResultsLock As New Object
Dim TokenSource As New CancellationTokenSource

Try

'启动 CurseForge 线程
Dim CurseForgeUrl As String = Task.Input.GetCurseForgeAddress()
Dim CurseForgeFailed As Boolean = False
If CurseForgeUrl IsNot Nothing Then
CurseForgeThread = RunInNewThread(
CurseForgeThread = RunInNewTask(
Sub()
Try
'获取工程列表
Expand All @@ -993,14 +996,14 @@ Retry:
[Error] = ex
CurseForgeFailed = True
End Try
End Sub, "CurseForge Project Request")
End Sub, "CurseForge Project Request", , TokenSource.Token)
End If

'启动 Modrinth 线程
Dim ModrinthUrl As String = Task.Input.GetModrinthAddress()
Dim ModrinthFailed As Boolean = False
If ModrinthUrl IsNot Nothing Then
ModrinthThread = RunInNewThread(
ModrinthThread = RunInNewTask(
Sub()
Try
Log("[Comp] 开始从 Modrinth 获取工程列表:" & ModrinthUrl)
Expand All @@ -1026,13 +1029,13 @@ Retry:
[Error] = ex
ModrinthFailed = True
End Try
End Sub, "Modrinth Project Request")
End Sub, "Modrinth Project Request", , TokenSource.Token)
End If

'等待线程结束
If CurseForgeThread IsNot Nothing Then CurseForgeThread.Join()
If CurseForgeThread IsNot Nothing Then CurseForgeThread.Wait()
If Task.IsAborted Then Exit Sub '会自动触发 Finally
If ModrinthThread IsNot Nothing Then ModrinthThread.Join()
If ModrinthThread IsNot Nothing Then ModrinthThread.Wait()
If Task.IsAborted Then Exit Sub

'确保存在结果
Expand Down Expand Up @@ -1061,8 +1064,7 @@ Retry:
End If

Finally
If CurseForgeThread IsNot Nothing Then CurseForgeThread.Interrupt()
If ModrinthThread IsNot Nothing Then ModrinthThread.Interrupt()
TokenSource.Cancel()
End Try

#End Region
Expand Down
6 changes: 3 additions & 3 deletions Plain Craft Launcher 2/Modules/Minecraft/ModLaunch.vb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ NextInner:
Private Sub McLaunchMemoryOptimize(Loader As LoaderTask(Of Integer, Integer))
McLaunchLog("内存优化开始")
Dim Finished As Boolean = False
RunInNewThread(
RunInNewTask(
Sub()
PageOtherTest.MemoryOptimize(False)
Finished = True
Expand Down Expand Up @@ -239,7 +239,7 @@ NextInner:
If CurrentLaunchOptions?.SaveBatch Is Nothing AndAlso '保存脚本时不提示
Not Setup.Get("HintBuy") AndAlso Setup.Get("LoginType") <> McLoginType.Ms Then
If IsSystemLanguageChinese() Then
RunInNewThread(
RunInNewTask(
Sub()
Select Case Setup.Get("SystemLaunchCount")
Case 3, 8, 15, 30, 50, 70, 90, 110, 130, 180, 220, 280, 330, 380, 450, 550, 660, 750, 880, 950, 1100, 1300, 1500, 1700, 1900
Expand Down Expand Up @@ -1038,7 +1038,7 @@ Retry:
Throw New Exception("$登录尝试太过频繁,请等待几分钟后再试!")
ElseIf Message.Contains("(404)") Then
Log(ex, "微软登录第 7 步汇报 404")
RunInNewThread(
RunInNewTask(
Sub()
Select Case MyMsgBox("请先创建 Minecraft 玩家档案,然后再重新登录。", "登录失败", "创建档案", "取消")
Case 1
Expand Down
4 changes: 2 additions & 2 deletions Plain Craft Launcher 2/Modules/Minecraft/ModMod.vb
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ Finished:
Dim EndedThreadCount As Integer = 0, IsFailed As Boolean = False
Dim MainThread As Thread = Thread.CurrentThread
'从 Modrinth 获取信息
RunInNewThread(
RunInNewTask(
Sub()
Try
'步骤 1:获取 Hash 与对应的工程 ID
Expand Down Expand Up @@ -1006,7 +1006,7 @@ Finished:
End Try
End Sub, "Mod List Detail Loader Modrinth")
'从 CurseForge 获取信息
RunInNewThread(
RunInNewTask(
Sub()
Try
'步骤 1:获取 Hash 与对应的工程 ID
Expand Down
6 changes: 3 additions & 3 deletions Plain Craft Launcher 2/Modules/Minecraft/ModWatcher.vb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
AddHandler GameProcess.ErrorDataReceived, AddressOf LogReceived

'初始化时钟
RunInNewThread(
RunInNewTask(
Sub()
Try
Do Until State = MinecraftState.Ended OrElse State = MinecraftState.Crashed OrElse State = MinecraftState.Canceled OrElse Loader.State = LoadState.Aborted
Expand Down Expand Up @@ -277,7 +277,7 @@
IsWindowFinished = True
'最大化
If Setup.Get("LaunchArgumentWindowType") = 4 Then
RunInNewThread(
RunInNewTask(
Sub()
Try
'如果最大化导致屏幕渲染大小不对,那是 MC 的 Bug,不是我的 Bug
Expand Down Expand Up @@ -350,7 +350,7 @@
WatcherLog("Minecraft 已崩溃,将在 2 秒后开始崩溃分析")
Hint("检测到 Minecraft 出现错误,错误分析已开始……")
FeedbackInfo()
RunInNewThread(
RunInNewTask(
Sub()
Try
Thread.Sleep(2000)
Expand Down
4 changes: 2 additions & 2 deletions Plain Craft Launcher 2/Modules/ModMain.vb
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ NextFile:
End If
End Sub
Public Sub TimerMainStart()
RunInNewThread(
RunInNewTask(
Sub()
Try
Do While True
Expand All @@ -955,7 +955,7 @@ NextFile:
End Try
End Sub, "Timer Main")
If Not IsAprilEnabled Then Exit Sub
RunInNewThread(
RunInNewTask(
Sub()
Try
Dim LastTime = My.Computer.Clock.TickCount
Expand Down
2 changes: 1 addition & 1 deletion Plain Craft Launcher 2/Modules/ModMusic.vb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
If Address Is Nothing Then Return
Log("[Music] 播放开始:" & Address)
MusicCurrent = Address
RunInNewThread(Sub() MusicLoop(IsFirstLoad), "Music", ThreadPriority.BelowNormal)
RunInNewTask(Sub() MusicLoop(IsFirstLoad), "Music", ThreadPriority.BelowNormal)
End Sub

'播放与暂停
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ Retry:
Public Sub McDownloadForgeRecommendedRefresh()
If IsForgeRecommendedRefreshed Then Exit Sub
IsForgeRecommendedRefreshed = True
RunInNewThread(Sub()
RunInNewTask(Sub()
Try
Log("[Download] 刷新 Forge 推荐版本缓存开始")
Dim Result As String = NetGetCodeByLoader("https://bmclapi2.bangbang93.com/forge/promos")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@
Public Shared CachedFolder As String = Nothing '仅在本次缓存的下载文件夹
Public Sub Save_Click(sender As Object, e As EventArgs)
Dim File As CompFile = If(TypeOf sender Is MyListItem, sender, sender.Parent).Tag
RunInNewThread(
RunInNewTask(
Sub()
Try
Dim Desc As String = If(Project.Type = CompType.ModPack, "整合包", If(Project.Type = CompType.Mod, "Mod ", "资源包"))
Expand Down
2 changes: 1 addition & 1 deletion Plain Craft Launcher 2/Pages/PageLaunch/MyMsgLogin.xaml.vb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
Btn1.EventData = Website
Btn2.EventData = UserCode
'启动工作线程
RunInNewThread(AddressOf WorkThread, "MyMsgLogin")
RunInNewTask(AddressOf WorkThread, "MyMsgLogin")
End Sub

Private Sub WorkThread()
Expand Down
Loading