- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
希望有大侠帮帮我!
几天前,我正在使用 Powershell 工具,该工具在屏幕角落显示仪表板,以提供计算机的一些网络“实时”诊断。此仪表板可以在通知区域中最小化。
首先,我创建了一个获取诊断信息并在表单上显示状态的函数。我试图用计时器刷新数据(参见:Real Time Data With Powershell GUI)。
问题是我的函数执行时间太长,它卡住了界面。所以表单上的按钮不再可用……(参见:Mouse event don't work after first timer Tick)。
现在,我尝试使用后台作业。我的想法是在循环模式下启动一个工作,并在一个计时器间隔内获取他的状态。
首先,Job 无法调用在我的主脚本中声明的函数(第 361 行)。我知道我可以使用全局和/或不使用函数,而是直接在 ScriptBlock 上编写代码但是......即使这样,我也不知道如何让工作循环并按间隔获取他的状态(第 368 行)…
你可以看到我并没有真正在 PowerShell 和 GUI 中进行过实验......我已经有一段时间没有开发它了,它是用另一种语言......
预先感谢您的帮助
如果你想运行它,我已经在这里上传了图像文件夹:
https://omerta.is/2A1L
下面是我的代码
####################################### FUNCTIONS ########################################
#Get diagnostics status
function GetStatus
{
#Create a return table
[hashtable]$Return = @{}
###Test LAN adapter###
$EthernetAdapter = (Get-WMIObject Win32_NetworkAdapter | Select Name, NetConnectionStatus | Where Name -like "*Gigabit*")
If ($EthernetAdapter -ne $null)
{
If ($EthernetAdapter.NetConnectionStatus -eq 2)
{$Return.LANOnStatus = $True}
else
{$Return.LANOnStatus = $False}
}
else
{
$Return.LANOnStatus = $False
}
###Test Wi-Fi adapter###
$WiFiAdapter = (Get-WMIObject Win32_NetworkAdapter | Select Name, NetConnectionStatus | Where Name -like "*Wireless*")
If ($WiFiAdapter -ne $null)
{
If ($WiFiAdapter.NetConnectionStatus -eq 2)
{$Return.WiFiOnStatus = $True}
else
{$Return.WiFiOnStatus = $False}
}
else
{
$Return.WiFiOnStatus = $False
}
###Test Network (Default Gateway Reachable)###
$DefaultGateway = (Get-WmiObject -Class Win32_IP4RouteTable | where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0'} | Sort-Object metric1 | select nexthop, metric1, interfaceindex).nexthop
If ($DefaultGateway -ne $null)
{
If (Test-Connection -ComputerName $DefaultGateway -Count 1 -TTL 4 -Quiet)
{$Return.NetworkStatus = $True}
else
{$Return.NetworkStatus = $False}
}
else
{
$Return.NetworkStatus = $False
}
#Test Internet connection
$GoogleWebSite = "www.google.com"
Try
{$Return.GoogleStatus = Test-Connection -ComputerName $GoogleWebSite -Count 1 -TTL 64 -Quiet}
Catch
{$Return.GoogleStatus = $False}
###DontReplyToo###
$DontReplyTooWebSite = "mdm.pictet.com"
Try
{$Return.DontReplyTooStatus = Test-Connection -ComputerName $DontReplyTooWebSite -Count 1 -TTL 64 -Quiet}
Catch
{$Return.DontReplyTooStatus = $False}
###DONT REPLY###
$DontReplyWebsite = "www.idontreply.com"
Try
{$Return.DontReplyStatus = Test-Connection -ComputerName $DontReplyWebsite -Count 1 -TTL 64 -Quiet}
Catch
{$Return.DontReplyStatus = $False}
#Return the table
Return $Return
}
########################################### EVENTS ###########################################
#Manual Synchronization
function ManualSync
{
Sync-Content
}
#Open Browser from dashboard
function Open-Browser
{
&($BrowserExe)
}
#Open a help message on click on help icon
function Open-Help($HelpText)
{
[System.Windows.Forms.MessageBox]::Show($HelpText,"Hotlines",0,32)
}
#Close Dashboard form on click on minimize icon
function Minimize-Dashboard
{
#Close Dashboard on click minimize
$Form.WindowState = "Minimize"
$Form.Visible = $False
$objNotifyIcon.Visible = $True
#!!!!! TO CHECK !!!!!
Wait-Event -Timeout 15 -SourceIdentifier NotifyIcon_Event
Remove-Event -SourceIdentifier NotifyIcon_Event
}
#Open Dashboard form on double click on agent icon in notification area
function OpenDashboard
{
#Open Dashboard on double-click
$Form.Visible = $True
$Form.WindowState = "Normal"
}
######################################### ASSEMBLIES #########################################
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Timers")
[void] [System.Windows.Forms.Application]::EnableVisualStyles()
######################################### VAR & CONST ########################################
#Screen placement
$Screen = [system.windows.forms.screen]::PrimaryScreen
$FormPos = $Screen.Bounds.Width - 160
#Dashboard Timer
$Timer = New-Object 'System.Windows.Forms.Timer'
$Timer.Interval = 3000
#Home directory of the program
$HomeDir = Split-Path $script:MyInvocation.MyCommand.Path
#Dashboard Images
$Background = [system.drawing.image]::FromFile("$HomeDir\img\interface.png")
$GreenLight = [system.drawing.image]::FromFile("$HomeDir\img\greenlight.png")
$RedLight = [system.drawing.image]::FromFile("$HomeDir\img\redlight.png")
$SyncImg = [system.drawing.image]::FromFile("$HomeDir\img\sync.png")
$BrowserImg = [system.drawing.image]::FromFile("$HomeDir\img\browser.png")
$HelpImg = [system.drawing.image]::FromFile("$HomeDir\img\help.png")
$MinimizeImg = [system.drawing.image]::FromFile("$HomeDir\img\minimize.png")
#Agent Images
$IconStd = New-Object system.drawing.icon ("$HomeDir\img\icon.ico")
$IconFocus = New-Object system.drawing.icon ("$HomeDir\img\icon_focus.ico")
#Log files
$LogLastSync = ("$HomeDir\Logs\LastSync.log")
$LogSyncAgent = ("$HomeDir\Logs\SyncAgentError.log")
#Browser Module
$BrowserExe = "$HomeDir\bin\Browser.exe"
#Free File Sync Module
$SyncAgentExe = "$HomeDir\bin\SyncAgent.exe"
$SyncJob = "$HomeDir\bin\SyncSettings.xml"
#Strings
$HelpText = "Hotline: 432423432423423"
########################################### FORMS ###########################################
#Dashboard Windows Forms
$Form = New-Object System.Windows.Forms.Form
$Font = New-Object System.Drawing.Font("Arial Unicode MS",10,[System.Drawing.FontStyle]::Bold)
$Lb_LANOn = New-Object System.Windows.Forms.Label
$Lb_WiFiOn = New-Object System.Windows.Forms.Label
$Lb_Network = New-Object System.Windows.Forms.Label
$Lb_Google = New-Object System.Windows.Forms.Label
$Lb_DontReplyToo = New-Object System.Windows.Forms.Label
$Lb_DontReply = New-Object System.Windows.Forms.Label
$Pb_LANOn = New-Object System.Windows.Forms.PictureBox
$Pb_WiFiOn = New-Object System.Windows.Forms.PictureBox
$Pb_Network = New-Object System.Windows.Forms.PictureBox
$Pb_Google = New-Object System.Windows.Forms.PictureBox
$Pb_DontReplyToo = New-Object System.Windows.Forms.PictureBox
$Pb_DontReply = New-Object System.Windows.Forms.PictureBox
$Pb_Sync = New-Object System.Windows.Forms.PictureBox
$Pb_Browser = New-Object System.Windows.Forms.PictureBox
$Pb_Help = New-Object System.Windows.Forms.PictureBox
$Pb_Minimize = New-Object System.Windows.Forms.PictureBox
#Agent Windows Form
$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon
$objNotifyIcon.Add_Click({OpenDashboard})
Register-ObjectEvent $objNotifyIcon Click NotifyIcon_Event
#Dashboard Interface Generation
$Form.Size = '150, 220'
$Form.FormBorderStyle = 'None'
$Form.Name = "Form"
$Form.StartPosition = 'Manual'
$Form.Location = $FormPos.ToString()+', 10'
$Form.Text = "Dashboard"
$Form.Font = $Font
$Form.BackgroundImage = $Background
$Form.BackgroundImageLayout = "None"
$Form.TransparencyKey = "White"
$Form.BackColor = "White"
#$Form.Opacity = '.85'
$Form.Controls.Add($Lb_LANOn)
$Lb_LANOn.Location = '10, 30'
$Lb_LANOn.Size = '75, 20'
$Lb_LANOn.Text = "LAN On"
$Lb_LANOn.ForeColor = 'Gray'
$Lb_LANOn.BackColor = "Transparent"
$Form.Controls.Add($Lb_WiFiOn)
$Lb_WiFiOn.Location = '10, 55'
$Lb_WiFiOn.Size = '75, 20'
$Lb_WiFiOn.Text = "Wi-Fi On"
$Lb_WiFiOn.ForeColor = 'Gray'
$Lb_WiFiOn.BackColor = "Transparent"
$Form.Controls.Add($Lb_Network)
$Lb_Network.Location = '10, 80'
$Lb_Network.Size = '75, 20'
$Lb_Network.Text = "Network"
$Lb_Network.ForeColor = 'Gray'
$Lb_Network.BackColor = "Transparent"
$Form.Controls.Add($Lb_Google)
$Lb_Google.Location = '10, 105'
$Lb_Google.Size = '75, 20'
$Lb_Google.Text = "Google"
$Lb_Google.ForeColor = 'Gray'
$Lb_Google.BackColor = "Transparent"
$Form.Controls.Add($Lb_DontReplyToo)
$Lb_DontReplyToo.Location = '10, 130'
$Lb_DontReplyToo.Size = '75, 20'
$Lb_DontReplyToo.Text = "DontReplyToo"
$Lb_DontReplyToo.ForeColor = 'Gray'
$Lb_DontReplyToo.BackColor = "Transparent"
$Form.Controls.Add($Lb_DontReply)
$Lb_DontReply.Location = '10, 155'
$Lb_DontReply.Size = '75, 20'
$Lb_DontReply.Text = "Dont Reply"
$Lb_DontReply.ForeColor = 'Gray'
$Lb_DontReply.BackColor = "Transparent"
$Form.Controls.Add($Pb_LANOn)
$Pb_LANOn.Location = '115, 33'
$Pb_LANOn.Size = '15, 15'
$Pb_LANOn.Image = $RedLight
$Pb_LANOn.BackColor = "Transparent"
$Form.Controls.Add($Pb_WiFiOn)
$Pb_WiFiOn.Location = '115, 58'
$Pb_WiFiOn.Size = '15, 15'
$Pb_WiFiOn.Image = $RedLight
$Pb_WiFiOn.BackColor = "Transparent"
$Form.Controls.Add($Pb_Network)
$Pb_Network.Location = '115, 83'
$Pb_Network.Size = '15, 15'
$Pb_Network.Image = $RedLight
$Pb_Network.BackColor = "Transparent"
$Form.Controls.Add($Pb_Google)
$Pb_Google.Location = '115, 108'
$Pb_Google.Size = '15, 15'
$Pb_Google.Image = $RedLight
$Pb_Google.BackColor = "Transparent"
$Form.Controls.Add($Pb_DontReplyToo)
$Pb_DontReplyToo.Location = '115, 133'
$Pb_DontReplyToo.Size = '15, 15'
$Pb_DontReplyToo.Image = $RedLight
$Pb_DontReplyToo.BackColor = "Transparent"
$Form.Controls.Add($Pb_DontReply)
$Pb_DontReply.Location = '115, 158'
$Pb_DontReply.Size = '15, 15'
$Pb_DontReply.Image = $RedLight
$Pb_DontReply.BackColor = "Transparent"
#Toolbar
$Form.Controls.Add($Pb_Sync)
$Pb_Sync.Location = '20, 195'
$Pb_Sync.Size = '20, 20'
$Pb_Sync.Image = $SyncImg
$Pb_Sync.BackColor = "Transparent"
$Pb_Sync.Add_Click({Sync-Content})
$Form.Controls.Add($Pb_Browser)
$Pb_Browser.Location = '51, 195'
$Pb_Browser.Size = '20, 20'
$Pb_Browser.Image = $BrowserImg
$Pb_Browser.BackColor = "Transparent"
$Pb_Browser.Add_Click({Open-Browser})
$Form.Controls.Add($Pb_Help)
$Pb_Help.Location = '82, 195'
$Pb_Help.Size = '20, 20'
$Pb_Help.Image = $HelpImg
$Pb_Help.BackColor = "Transparent"
$Pb_Help.Add_Click({Open-Help($HelpText)})
$Form.Controls.Add($Pb_Minimize)
$Pb_Minimize.Location = '113, 195'
$Pb_Minimize.Size = '20, 20'
$Pb_Minimize.Image = $MinimizeImg
$Pb_Minimize.BackColor = "Transparent"
$Pb_Minimize.Add_Click({Minimize-Dashboard})
########## MAIN
#Status Init
#$Status = GetStatus
#Create the Status Background Job
Start-Job -Name "jobGetStatus" -ScriptBlock {$Status = GetStatus} #function not recognized by Background Job
#Wait for job result
While (Get-Job -Name "jobGetStatus" | where { $_.State -eq "Running" })
{Start-Sleep 1}
#Get Status on Timer Tick
$Timer.Add_Tick({Get-Job -Name "jobGetStatus" | Receive-Job}) #job not updated
#Display new status on tick
$Timer.Add_Tick({
#LAN
If ($Status.LANOnStatus -eq $True)
{$Pb_LANOn.Image = $GreenLight}
else
{$Pb_LANOn.Image = $RedLight}
#WIFI
If ($Status.WiFiOnStatus -eq $True)
{$Pb_WiFiOn.Image = $GreenLight}
else
{$Pb_WiFiOn.Image = $RedLight}
#NETWORK
If ($Status.NetworkStatus -eq $True)
{$Pb_Network.Image = $GreenLight}
else
{$Pb_Network.Image = $RedLight}
#GOOGLE
If ($Status.GoogleStatus -eq $True)
{$Pb_Google.Image = $GreenLight}
else
{$Pb_Google.Image = $RedLight}
#DontReplyToo
If ($Status.DontReplyTooStatus -eq $True)
{$Pb_DontReplyToo.Image = $GreenLight}
else
{$Pb_DontReplyToo.Image = $RedLight}
#BING
If ($Status.DontReplyStatus -eq $True)
{$Pb_DontReply.Image = $GreenLight}
else
{$Pb_DontReply.Image = $RedLight}
})
#Start Timer
$Timer.Enabled = $True
#Agent Init
$objNotifyIcon.Icon = $IconStd
$objNotifyIcon.Text = "Dashboard"
$objNotifyIcon.Visible = $True
#Show Interface
$Form.ShowDialog()
############## END
最佳答案
不错的小工具。
我删除了对 Job
的所有引用,并将作业中的代码添加到 Tick 本身中:
$Timer.Add_Tick({
$Status = GetStatus
#LAN
If ($Status.LANOnStatus -eq $True)
{$Pb_LANOn.Image = $GreenLight}
else
{$Pb_LANOn.Image = $RedLight}
...
})
关于user-interface - 在脚本运行时刷新表单上的数据的后台作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33639213/
我有 powershell 脚本。通过调度程序,我运行 bat 文件,该文件运行 PS1 文件。 BAT文件 Powershell.exe -executionpolicy remotesigned
什么更快? 或者 $.getScript('../js/SOME.js', function (){ ... // with $.ajaxSetup({ cache: true });
需要bash脚本来显示文件 #!/bin/bash my_ls() { # save current directory then cd to "$1" pushd "$1" >/dev/nu
我有一个输入 csv 文件,实际上我需要在输入文件中选择第 2 列和第 3 列值,并且需要转换两个值的时区(从 PT 到 CT),转换后我需要替换转换后的时区值到文件。 注意: 所有输入日期值都在太平
我正在使用/etc/init.d/httpd 作为 init.d 脚本的模板。我了解文件中发生的所有内容,但以下行除外: LANG=$HTTPD_LANG daemon --pidfile=${pid
我有以下选择: python runscript.py -O start -a "-a "\"-o \\\"-f/dev/sda1 -b256k -Q8\\\" -l test -p maim\""
我对 shell 脚本完全陌生,但我需要编写一个 shell 脚本来检查文件是否存在,然后移动到另一个位置 这是我写的: 一旦设备崩溃,我就会在/storage/sdcard1/1 中收集日志 #!/
我正在使用 bash 脚本从文本文件中读取数据。 数据: 04:31 Alex M.O.R.P.H. & Natalie Gioia - My Heaven http://goo.gl/rMOa2q
这是单击按钮时运行的 javascript 的结尾 xmlObj.open ('GET', /ajax.php, true); xmlObj.send (''); } 所以这会执行根目录中的php脚本
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我需要将文件转换为可读流以通过 api 上传,有一个使用 fs.createReadStream 的 Node js 示例。任何人都可以告诉我上述声明的 python 等价物是什么? 例子 const
我有一个 shell 脚本 cron,它从同一目录调用 python 脚本,但是当这个 cron 执行时,我没有从我的 python 脚本中获得预期的输出,当我手动执行它时,我的 python 脚本的
如何使 XMLHttpRequest (ajax) 调用的 php 脚本安全。 我的意思是,不让 PHP 文件通过直接 url 运行,只能通过脚本从我的页面调用(我不想向未登录的用户显示数据库结果,并
我正在尝试添加以下内容 我正在使用经典的 asp。但我不断收到的错误是“一个脚本 block 不能放在另一个脚本 block 内。”我尝试了此处的 document.write 技术:Javasc
如何从另一个 PHP 脚本(如批处理文件)中运行多个 PHP 脚本?如果我了解 include 在做什么,我认为 include 不会起作用;因为我正在运行的每个文件都会重新声明一些相同的函数等。我想
我想创建具有动态内容的网页。我有一个 HTML 页面,我想从中调用一个 lua 脚本 如何调用 lua 脚本? ? ? 从中检索数据?我可以做类似的事情吗: int xx = 0; xx
我删除了我的第一个问题,并重新编写了更多细节和附加 jSfiddle domos。 我有一个脚本,它运行查询并返回数据,然后填充表。表中的行自动循环滚动。所有这些工作正常,并通过使用以下代码完成。然而
我尝试使用 amp 脚本,但收到此错误: “[amp-script] 脚本哈希未找到。amp-script[script="hello-world"].js 必须在元[name="amp-script
我有一个读取输入的 Shell 脚本 #!/bin/bash echo "Type the year that you want to check (4 digits), followed by [E
我正在从 nodejs 调用 Lua 脚本。我想传递一个数组作为参数。我在 Lua 中解析该数组时遇到问题。 下面是一个例子: var script = 'local actorlist = ARGV
我是一名优秀的程序员,十分优秀!