摘要:
一个简单的Form, 按钮btnTest是enabled=false。在btnEnable的Click事件中 创建线程,在线程中尝试设置btnTest.Enabled = true; 发生异常:线程间操作无效: 从不是创建控件“btnTest”的线程访问它。代码如下: 1 using System; 2 using System.Threading; 3 using System.Windows.Forms; 4 5 namespace TestingUIThread 6 { 7 public partial class Form1 : Form 8 { 9 ... 阅读全文
摘要:
在C#中调用powershell脚本,需要引用的namespace如下:using System.Management.Automation;using System.Management.Automation.Runspaces;添加System.Management.Automation.dll的引用,需要使用浏览,如果不知道位置,可以先在本机查找下。代码如下: 1 //RunPowershell(@".\x.ps1", ""); 2 private Collection<PSObject> RunPowershell(string fi 阅读全文
摘要:
本文包括使用powershell启动、关闭Hyper-V虚拟机,及获得虚拟机状态、虚拟机快照、根据快照回滚虚拟机。1. 启动 1 param 2 ( 3 [string]$hostServer = $(throw "param -host server is required."), 4 [string]$vmName = $(throw "param -virtual machine name is required.") 5 ) 6 7 function GetImageState 8 { 9 param10 (11 [string]... 阅读全文
摘要:
Hyper-V WMI Provider工具类如下:using System;using System.Collections.Generic;using System.Management;namespace MyNamespace{ #region Return Value of RequestStateChange Method of the Msvm_ComputerSystem Class //Return Value of RequestStateChange Method of the Msvm_ComputerSystem Class //This meth... 阅读全文
摘要:
Get the operating system info by using the classes from namespace System.Management. OS: Windows XP, Vista, Win7, Windows Server 2008 and so on. 1 using System; 2 using System.Management; 3 4 namespace GetOSInfo_Peter 5 { 6 class Program 7 { 8 static void Main(string[] args) 9 ... 阅读全文
摘要:
阅读全文
摘要:
MDI,全称是多文档界面(Multiple Document Interface),主要应用于基于图形用户界面的系统中。其目的是同时打开和显示多个文档,便于参考和编辑资料。 下面是一个WinForm MDI小例子。 1 using System; 2 using System.Windows.Forms; 3 4 namespace WinFormMDI 5 { 6 public partial class FrmMain : Form 7 { 8 public FrmMain() 9 {10 InitializeCo... 阅读全文
摘要:
WebClient 提供的向 URI 标识的资源发送数据和从 URI 标识的资源接收数据的公共方法。使用时需要将捕捉到的Http头部放入Headers中。(捕获http可以使用HttpWatch)WebClient wc = new WebClient();wc.Credentials = new NetworkCredential(username, password); //对于需要登录的网站设置验证信息wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");string 阅读全文
摘要:
问题:HTTP 错误 404.13 - Not Found 请求筛选模块被配置为拒绝超过请求内容长度的请求。原因:Web 服务器上的请求筛选被配置为拒绝该请求,因为内容长度超过配置的值(IIS 7 默认文件上传大小时30M)。解决:更改asp.net文件上传大小限制1. 修改IIS的applicationhost.config 文件位置: %windir%/system32/inetsrv/config/applicationhost.config 找到<requestFiltering>节点,该节点下默认没有 <requestLimits maxAllowedContent 阅读全文