重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
using System;
创新互联专注于企业全网营销推广、网站重做改版、红河网站定制设计、自适应品牌网站建设、H5开发、商城开发、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为红河等各大城市提供网站开发制作服务。
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Process.Start("cmd");//启动CMD
}
}
}
给你个多线程执行任务的例子
先添加BackgroundWorker1、TextBox1、Button1,都是标准控件(窗体)在工具箱中找
vb.net2008
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BackgroundWorker1.WorkerReportsProgress = True '可以传值
BackgroundWorker1.WorkerSupportsCancellation = True '可以暂停
TextBox1.Text = "开始多任务"
Button1.Text = "0"
BackgroundWorker1.RunWorkerAsync() '调用多任务程序
End Sub
'多任务程序
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
System.Threading.Thread.Sleep(20000) '暂停时间,可以是你的非常耗时程序任务
BackgroundWorker1.ReportProgress(100) '传出0-100数值
End Sub
'接收传出数值
Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
'TextBox1.Text = e.ProgressPercentage
TextBox1.Text = "结束多任务"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Text += 1
End Sub
End Class
在启动程序后可以不停点击Button1看到数值的增加而不会卡死,20秒后TextBox1就会改成"结束多任务",实际上看你的程序是什么了,传值和接收传出数值的部分可取消
两种方法
1.
Shell(""Explorer.exe", AppWinStyle.NormalFocus")
2.
Dim proc As New Process
proc.StartInfo.FileName="Explorer.exe"
proc.Start
方法2给予更多的控制,如结束进程的方法Kill