Android跑马灯进度条,跑马灯进度条在Powershell中冻结
我一直在使用Powershell一段时间,它不是理想的编程环境,但却被我的程序困住了。跑马灯进度条在Powershell中冻结
我的程序是一个带有选取框进度条和搜索作业的GUI。
我的程序执行的操作:使用Powershell运行脚本后,如果模式为MTA,它将在STA模式下重新启动Powershell。之后,它会要求提供一个文件夹位置。输入文件夹位置后,它将开始搜索作业,并将搜索文件的位置。每个文件都将被存储到一个数组中。该数组将打印到将保存在桌面上的tempfile.txt中。同时,该作业正在搜索GUI将使用滚动进度条显示表单的文件。
我的程序需要做什么:在作业完成搜索和存储文件后,它必须关闭表单。
我已经尝试过使用$ formSearchingFiles.Close()命令,但我注意到乔布斯无法关闭他们的“父”线程,所以这项工作将无法关闭窗体。
我也尝试使用Wait-Job cmdlet解决问题,但然后“选框进度”栏会冻结,否则表单根本不会显示。
我已经看过很多互联网的解决方案,但我找不到适合这个问题的。我正在考虑多处理,但我不知道这是否可能在PowerShell 2.0中(我限制在2.0或更低)。
我也不知道Search-Job是否可以通知主线程完成任务,以便主线程可以继续执行程序,而不冻结进度条。
我希望我已经解释了有关程序和我的问题。
# Get the path of the script
$scriptPath = ((Split-Path $script:MyInvocation.MyCommand.Path) + "\")
$scriptName = $MyInvocation.MyCommand.Name
$script = $scriptPath + $scriptName
# Check if powershell is running in STA(Single Threaded Apartment) or MTA(Multi Threaded Apartment) mode.
# If it is running in MTA mode then restart Powershell in STA mode.
if ([threading.thread]::CurrentThread.GetApartmentState() -eq "MTA")
{
Write-Host Restarting Powershell in STA mode
& $env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -sta "& {&'$script'}"
}
else
{
$folderPath = $currentFolderLocation.Text
$tempFile = $currentStagingLocation.Text
$tempFile += "\fileArray.txt"
function OnApplicationLoad {
return $true #return true for success or false for failure
}
function OnApplicationExit {
$script:ExitCode = 0 #Set the exit code for the Packager
}
function Call-Searching_pff {
[void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[void][reflection.assembly]::Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[System.Windows.Forms.Application]::EnableVisualStyles()
$formSearchingFiles = New-Object 'System.Windows.Forms.Form'
$label = New-Object 'System.Windows.Forms.Label'
$progressbar = New-Object 'System.Windows.Forms.ProgressBar'
$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
$FormEvent_Load={
$folderPath = &read-host "Enter path"
$tempFile = (([Environment]::GetFolderPath("Desktop")) + "\tempfile.txt")
$SearchJob = Start-Job -scriptblock {
param ($folderPath, $tempFile)
$fileArray = @()
# Get all files and folders under the specified path
$items = Get-ChildItem -Path $folderPath -Recurse
foreach ($item in $items)
{
# Check if the item is a file or a folder
if (!($item.PSIsContainer))
{
# Extract path of file with path of entered folder
$extractedPath = $item.FullName
$extractedPath = $extractedPath.Replace($folderPath, "")
$fileArray += $extractedPath
}
}
# Save array in temporary file
$fileArray | out-file $tempFile
$formSearchingFiles.Close() #Does not work inside job :(
} -ArgumentList @($folderPath, $tempFile)
}
$Form_StateCorrection_Load=
{
#Correct the initial state of the form to prevent the .Net maximized form issue
$formSearchingFiles.WindowState = $InitialFormWindowState
}
$Form_Cleanup_FormClosed=
{
#Remove all event handlers from the controls
try
{
$formSearchingFiles.remove_Load($FormEvent_Load)
$formSearchingFiles.remove_Load($Form_StateCorrection_Load)
$formSearchingFiles.remove_FormClosed($Form_Cleanup_FormClosed)
}
catch [Exception]{ }
}
# formSearchingFiles
$formSearchingFiles.Controls.Add($label)
$formSearchingFiles.Controls.Add($progressbar)
$formSearchingFiles.ClientSize = '394, 122'
$formSearchingFiles.FormBorderStyle = 'FixedDialog'
$formSearchingFiles.MaximizeBox = $False
$formSearchingFiles.Name = "formSearchingFiles"
$formSearchingFiles.StartPosition = 'CenterScreen'
$formSearchingFiles.Text = "Compatibility Checker"
$formSearchingFiles.add_Load($FormEvent_Load)
# label
$label.Location = '12, 27'
$label.Name = "label"
$label.Size = '368, 26'
$label.TabIndex = 1
$label.Text = "Searching for files, please wait.."
$label.TextAlign = 'MiddleCenter'
# progressbar
$progressbar.Location = '12, 68'
$progressbar.MarqueeAnimationSpeed = 40
$progressbar.Name = "progressbar"
$progressbar.Size = '370, 30'
$progressbar.Style = 'Marquee'
$progressbar.TabIndex = 0
#Save the initial state of the form
$InitialFormWindowState = $formSearchingFiles.WindowState
#Init the OnLoad event to correct the initial state of the form
$formSearchingFiles.add_Load($Form_StateCorrection_Load)
#Clean up the control events
$formSearchingFiles.add_FormClosed($Form_Cleanup_FormClosed)
#Show the Form
return $formSearchingFiles.ShowDialog()
} #End Function
#Call OnApplicationLoad to initialize
if((OnApplicationLoad) -eq $true)
{
#Call the form
Call-Searching_pff | Out-Null
#Perform cleanup
OnApplicationExit
}
}
+0
为什么要使用一个WinForms进度条什么特别的原因?你见过write-progress cmdlet吗?它可以在控制台中为你呈现一个进度条,而不必担心所有这些STA垃圾。 –
+0
这个程序只是我的完整程序的一部分,我使用Windows窗体来制作一个漂亮的GUI,它比控制台中的文本更加用户友好。我刚刚发布了这篇文章,因为只有在这篇文章中我遇到了一个问题。 –
+0
我可能有解决方案。通过使用同步哈希表作为2个线程之间的“通信链接”。还没有测试过。 –
Android跑马灯进度条,跑马灯进度条在Powershell中冻结相关推荐
- android跑马灯有时候不跑
android跑马灯有时候不跑的解决方法 按照下面的设置顺序进行设置,否则在有的手机上可能不会有效果,比如三星GT i9300 @Override public boolean isFocused() ...
- Android自定义半圆进度条 半圆渐变色进度条带指示 半圆开口大小可自由修改
Android自定义半圆进度条 半圆渐变色进度条带指示 半圆开口大小可自由修改 首先我们来看下效果图 不同的开口大小只需要修改一个参数即可 半圆1: 半圆2: 半圆3: 如果是你想要的效果,就直接滑动 ...
- Android BGradualProgress 多种渐变、直角or弧角、进度条、加载条
可实现多种渐变.直角or弧角.进度条.加载条 (Various gradient, right or arc angle, progress bar and loading bar can be re ...
- 精通Android自定义View(十二)绘制圆形进度条
1 绘图基础简析 1 精通Android自定义View(一)View的绘制流程简述 2 精通Android自定义View(二)View绘制三部曲 3 精通Android自定义View(三)View绘制 ...
- Android可触摸圆形进度条,Android 可滚动圆形进度条 滑块和进度在进度条上面跟着滚动...
Android 可滚动圆形进度条 滑块和进度在进度条上面跟着滚动.package com.example.test; import android.content.Context; import an ...
- Android仿虾米音乐播放器之自定义进度条seekbar
先上图吧,仿照写的进度条 很明显不是系统的自带的进度条,所以我们需要自定义来实现这个效果,先看看官方给的例子 <layer-list xmlns:android="http://sch ...
- Android的进度条(ProgressBar)、拖动条(SeekBar)
Android的进度条与拖动条 一.ProgressBar(进度条) 进度条,ProgressBar,分为环形和水平条行, 首先看下效果图,Progress进度加载. 进度条XML中的属性 ...
- 【Android FFMPEG 开发】FFMPEG 视频播放进度控制 ( 显示播放进度 | 拖动进度条播放 )
文章目录 I . FFMPEG 播放进度控制 II . FFMPEG 播放视频 ( 效果展示 ) III . FFMPEG 获取视频时长 IV . FFMPEG 视频播放进度获取 V . FFMPEG ...
- android qq语音按钮,科技教程:如何在手机QQ中使用新版QQ语音进度条功能?
如今越来越多的小伙伴对于如何在手机QQ中使用新版QQ语音进度条功能?这方面的问题开始感兴趣,看似平静的每一天,在每个人身上都在发生着各种各样的故事,因为大家现在都是想要了解到此类的信息,那么既然现在大 ...
- android一格一格向上的进度条,如何 使用 ProgressBar 进度条
满意答案 dfsgvcx 2015.03.11 采纳率:52% 等级:9 已帮助:1019人 ProgressBar 控件通过从左到右用一些方块填充矩形来表示一个较长操作的进度.语法Progre ...
最新文章
- Python的WeRoBot框架开发公众号
- koa中间件mysql写法_koa-mysql(三)
- python-生成器函数进阶和各种推导式day15
- java 登录牵手_Java: HttpURLConnection 模拟登录方法 (带cookie 的Post/Get)_20160908_七侠镇莫尛貝...
- 反思本地与测试服一个接口不同的响应:本地正常测试服不行500错误,原因php版本新语法不一样
- html运用以及工具
- 【Boost】boost库中的小工具enable_shared_from_this
- linux之文件类型
- socket通信和异常处理札记
- c winform mysql类_C#连接MySQL数据库操作类
- Qt工作笔记-对QItemDelegate自定义委托的理解
- angularjs的三种注入方式
- Apache 虚拟主机
- idam oracle_oracle中的wm_concat对应达梦的是什么?
- editor.md实现拖拽剪切复制粘贴上传图片,文件插件
- Python网络爬虫与信息提取 - requests库入门
- 数量乘单价秋金额的计算机公式,在电子表格中数量乘以单价等于金额用什么样的公式啊?怎么算呢?...
- 查学籍网站报服务器错误,学籍系统常见问题
- sublime text 3143 授权码
- C# 判断正负数个数