【发布时间】:2014-10-03 15:20:20
【问题描述】:
虽然我有一些脚本编写经验(VBscript、PowerShell、批处理、shell 等),但我不是程序员。我只是要求你请善待!
简短:
作为 VB.NET 的新手,在将 Microsoft.Bcl.Async 包含到项目中之后,我需要帮助将 Await/Async .NET 4.5 代码重写为 .NET 4.0 兼容代码。这是修剪后的 .NET 4.5 代码:
Imports System
Imports System.IO
Imports System.Diagnostics
Imports System.Security.Principal
Private Sub buttonName_Click(sender As Object, e As EventArgs) Handles buttonName.Click
// Do a bunch of stuff
// like assign values of text boxes to variables
// validate input to a certain degree
// Run command
RunProcess("someexe.exe", "plenty of argments")
End Sub
Private Async Sub RunProcess(ByVal Command As String, Optional ByVal Arguments As String = "NOTSET")
// Function to disable all the fields and buttons
LockUI()
// Sow the progress bar
// Start the progress marquee so people know something's happening
ProgressBar1.Visible = True
ProgressBar1.Style = ProgressBarStyle.Marquee
ProgressBar1.MarqueeAnimationSpeed = 60
ProgressBar1.Refresh()
// Prepare process
Dim Execute As Process
If Arguments = "NOTSET" Then
Execute = Process.Start(Command)
Else
Execute = Process.Start(Command, Arguments)
End If
// Run the process and wait for it to finish
Await Task.Run(Sub() Execute.WaitForExit())
// Do some other stuff like check return code etc.
// Display positive msgbox for success
// Display failure message box for, well, failures
// Hide progress bar since we're done
ProgressBar1.Visible = False
// Unlock all the fields
UnlockUI()
End Sub
长:
我在 Visual Studio Premium 2013 中为仅控制台/基于命令行的应用程序编写了一个非常简单的 GUI 包装器。它实际上只不过是一个 VB Windows 窗体应用程序,带有一些用于用户输入的文本框和两个执行操作的按钮。当按下任一按钮时,它会使用从文本框中提取的参数来执行命令,并在运行时显示一个选框进度条,something I needed help with recently。
效果很好,我很激动,非常thankful。但是,我刚刚得知将在上使用的机器只有 .NET 4.0,而且没有时间推出 .NET 4.5。我看到可以在项目中更改目标框架的位置,但是在查看了一些资源(Link 1、Link 2、Link 3)之后,我不确定如何重新编写代码以与 Microsoft 一起使用。 Bcl.Async。
【问题讨论】:
-
代码可以编译吗?如果没有,错误是什么?
标签: .net vb.net .net-4.0 visual-studio-2013 async-await