格式为JPG,背景为蓝色反射分辨率,分辨率为390*567,大小不超过1M怎么弄

用C#设计Windows应用程序模板
&通常windows应用程序都有相似的特征:控件、菜单、工具条、状态栏等等。每次我们开始作一个新的windows应用程序时都是以相同的事情开始:建立项目,添加控件和事件处理器。如果我们有一个模板,那么我们就可以节约大量的时间了。 在介绍如何建立模板的过程中,将涉及大量的微软.net framework类库的基本知识。如果你没有使用集成开发环境那么本文介绍的模板对你将非常有用,如果你使用了visual studio.net这样的集成开发环境你也可以从中了解控件的工作方式,这对你也是很有用的。 写一个windows应用程序总是从下面的几个步骤开始:     1、创建一个窗体     2、给窗体添加控件     3、添加菜单和菜单项,并绑定到窗体上     4、创建工具条     5、添加状态栏     6、添加事件处理器 在windows应用程序开发中,你不可能完全跳过这些步骤,你可以对他作些修改,但不可能完全跳过。下面是完全的模板图:
screen.width-600)this.style.width=screen.width-600;" border=0>--------------图1 ----------- 创建窗体 在.Net FrameWork程序设计中,窗体总是System.Windows.Forms.Form类的子类,他继承聊着各类的全部特征,你甚至不用添加任何一行代码就可以创建window窗体了。现在我们创建一个form类的子类myapp,需要注意的是在说明继承时使用冒号:。
using System.Windows.F public class MyWinApp: Form { } 与其他程序相似,我们需要一个main()的主方法作为应用程序的入口。在main()中使用System.Windows.Forms的run方法来开始应用程序和显示窗体。run方法有三种重载方式,对于windows应用程序,我们采取重载一个窗体对象的方式:
public static void Main() { MyWinApp form = new MyWinApp(); Application.Run(form); } 作为选择,可以在main()方法中将两行代码写成一行: public static void Main() { Application.Run(new MyWinApp()); } 设置属性 一旦有了窗体,就可以设置它的属性(象高度、宽度、标题等)并指定一个象图1那样的图标,可以通过代码或从构造器重调用一个方法来完成这个设置。在list1中有一个方法InitializeComponent,可以将初始化代码写入其中。 使用width和height属性设置宽度和高度
this.Width = 400; this.Height = 300;
使用窗体的text属性设置标题
this.Text = "My Windows Application"; 设置图标 如果未作说明,windows应用程序将显示一个缺省图标,可以修改这个图标,方法是设置窗体的icon属性,这个属性接受一个System.Drawing.Icon对象。Icon类有几个可以用于初始化Icon对象的构造函数,需要说明的是最好提供.ico文件的完全路径。
this.Icon = new Icon(imageFolder + "applicationLogo.ico"); 这里 imageFolder是一个静态域,用于指示icon文件的目录,imageFolder的定义如下:
static String imageFolder = "Images" + Path.DirectorySeparatorChar.ToString(); 这告诉应用程序icon文件在应用程序的image目录下,这里使用了System.IO.Path 类的DirectorySeparatorChar属性获得操作系统用于分隔目录和父目录的分隔符,在这里没有使用"/",这是因为对于windows操作系统这是正确的,但对于linux和unix则不然。这也是为了证明模板对于其他操作系统也是方便的。 窗体的位置 使窗体居中时非常有用的,要达到这个目的,需要使用StartPosition属性,并将FormStartPosition 的一个成员赋给他。
this.StartPosition = FormStartPosition.CenterS 当然也可以用form类的CenterToScreen方法是窗体居中,但这个方法不能直接使用。
this.CenterToScreen();
form类还有其他一些让人感兴趣的属性和方法,这里列出了其中的部分:     1、设置Opacity 属性创建一个透明或半透明的窗体     2、设置modal属性使窗体为模式的或非模式的     3、通过BackColor属性改变窗体的背景颜色     4、将TopMost属性设置为true,以确定窗体在其他所有非最顶部窗体之上
给窗体添加控件& windows控件均继承自System.Windows.Forms.Control类,control类处理用户输入、安全等,他给窗体的控件提供了一个windows句柄,以及一些重要的属性,如Name, Enabled, Text, BackColor, Left, Top, Size, Location, Visible, Width, 和 Height。 System.Windows.Forms名称空间提供了12个控件,每一个控件都有它自己的属性和特征,所以在篇文章中我们不可能全部讨论。给窗体添加控减非常容易,下面的代码给窗体添加了三个控件,分别是:Label, Button, 和TreeView。
L B TreeV 为了简便,可以在声明的同时实例化这些对象。
Label label = new Label(); Button button = new Button(); TreeView tree = new TreeView();
然后在InitializeComponent方法中设置这些控件的属性,尤其是设置控件的大小和在窗体中的位置,对于大小可以使用width和height属性,比如treeview控件的大小可以使用下面的属性:
tree.Width = 100; tree.Height = 100; 确定控件的位置可以使用控件的left和top属性,这两个属性决定了控件的左上角的位置,就像下面的语句决定了treeview的位置:
tree.Top = 40; tree.Left = 20;
当然你也可以使用更简单的Location属性,将System.Drawing.Point结构的实例赋给他。我们用这种方法确定Label和Button的位置。
label.Location = new Point(220, 40); button.Location = new Point(220, 80); 下一步就是要使控件在窗体上可见。使用Form.ControlCollection类的add方法将每个控件添加到窗体的ControlCollection中,ControlCollection可以使用窗体的控件属性访问。
this.Controls.Add(label); this.Controls.Add(button); this.Controls.Add(tree); #p# 添加菜单和菜单项 要找到没有菜单的windows应用程序非常困难,菜单使访问应用程序的功能变得很简单,在大多数环境下可以最小的使用控件。菜单比控件占用更少的空间,同时使应用程序显得更有组织。 在System.Windows.Forms名称空间中,所有与菜单相关的控件都是menu类的子类。menu是一个抽象类,你不能直接实例化,menu类有三个子类:
ContextMenu MainMenu MenuItem &ContextMenu类表示快捷菜单,在控件或窗体区域点击鼠标右键时显示。快捷菜单常用于组合窗体mainmenu类的菜单项给出应用程序的上下文,这对于用户时非常有用的。& MainMenu表示传统的位于窗体顶部的菜单,你可以把它看成窗体菜单结构的容器。一个菜单是由MenuItem表示的菜单项组成的,对于应用程序而言每一个菜单项是一个命令或其它子菜单项的父菜单。form类都有一个menu属性,采用将mainmenu对象赋给menu属性的方式将mainmenu对象绑定到窗体。 在这个模板中,我们没有使用ContextMenu类,但我们示范了如何使用MainMenu和MenuItem类。我们首先需要在窗体中添加一个菜单,给窗体添加一个MainMenu对象。
MainMenu mainMenu = new MainMenu(); 现在MainMenu对象中什么都没有,下面我们给他添加一个MenuItem对象。在List1中主菜单称为fileMenuItem,它的text属性是&File,&表示他后面的字母带下划线,是该菜单的快捷键。通过使用Menu对象的MenuItemCollection的add方法为MainMenu添加一个或几个MenuItem,这个集合可以通过menu类的MenuItems属性访问。
MenuItem fileMenuItem = new MenuItem(); mainMenu.MenuItems.Add(fileMenuItem); 我们在fileMenuItem 菜单项中还添加了其它MenuItem,这些MenuItem是fileMenuItem的子菜单。你也可以给子菜单添加子菜单。图2显示了菜单的等级结构。
screen.width-600)this.style.width=screen.width-600;" border=0>---------图2--------- &菜单项的声明如下:
MenuItem fileNewMenuI MenuItem fileOpenMenuI MenuItem fileSaveMenuI MenuItem fileSaveAsMenuI MenuItem fileMenuWithS MenuItem submenuMenuI MenuItem fileExitMenuI MenuItem类有几个构造函数,使用这些构造函数实例化你的 MenuItem对象,并添加一个事件处理器。
// the following constructor is the same as: // menuItem fileNewMenuItem = new MenuItem(); // fileNewMenuItem.Text = "&New"; // fileNewMenuItem.Shortcut = Shortcut.CtrlN; // fileNewMenuItem.Click += new // System.EventHandler(this.fileNewMenuItem_Click); fileNewMenuItem = new MenuItem("&New", new System.EventHandler(this.fileNewMenuItem_Click), Shortcut.CtrlN); fileOpenMenuItem = new MenuItem("&Open", new System.EventHandler(this.fileOpenMenuItem_Click), Shortcut.CtrlO); fileSaveMenuItem = new MenuItem("&Save", new System.EventHandler(this.fileSaveMenuItem_Click), Shortcut.CtrlS); fileSaveAsMenuItem = new MenuItem("Save &As", new System.EventHandler(this.fileSaveAsMenuItem_Click)); fileMenuWithSubmenu = new MenuItem("&With Submenu"); submenuMenuItem = new MenuItem("Su&bmenu", new System.EventHandler(this.submenuMenuItem_Click)); fileExitMenuItem = new MenuItem("E&xit", new System.EventHandler(this.fileExitMenuItem_Click)); Event handling is discussed further in the section "Adding Event Handlers." As mentioned, the menu items are added to the fileMenuItem control. fileMenuItem.MenuItems.Add(fileNewMenuItem); fileMenuItem.MenuItems.Add(fileOpenMenuItem); fileMenuItem.MenuItems.Add(fileSaveMenuItem); fileMenuItem.MenuItems.Add(fileSaveAsMenuItem); fileMenuItem.MenuItems.Add(fileMenuWithSubmenu); fileMenuWithSubmenu.MenuItems.Add(submenuMenuItem); fileMenuItem.MenuItems.Add("-"); // add a separator fileMenuItem.MenuItems.Add(fileExitMenuItem);
注意在菜单项之间可以创建一个分隔符,方法是使用menu类的MenuItems集合的add方法。上面的例子中使用的分隔符是"-"。
创建工具条 为了使应用程序的界面更友好,可以在窗体中添加一个工具条。工具条由System.Windows.Forms.ToolBar类描述。窗体中可有多个工具条,工具条中包含了一个或多个ToolBarButton类描述的按钮,可以在每个按钮中插入图像或图标,要达到这个目的你需要一个ImageList控件作为图像容器。
ImageList imageList = new ImageList(); 对于每个图像文件首先要实例化为image对象,然后将这些图像添加到ImageList控件中,Image和Bitmap类可以在System.Drawing名称空间中找到。
Image newFileImage = new Bitmap(imageFolder + "newFile.bmp"); Image openFileImage = new Bitmap(imageFolder + "openFile.gif"); Image saveFileImage = new Bitmap(imageFolder + "saveFile.bmp"); Image printImage = new Bitmap(imageFolder + "print.gif"); . . . imageList.Images.Add(newFileImage); imageList.Images.Add(openFileImage); imageList.Images.Add(saveFileImage); imageList.Images.Add(printImage); 注意你可以使用Images集合的add方法将image对象加入到imagelist控件中。现在为将这些图加入到控件中,必须将ImageList控件赋给ToolBar的ImageList属性。
toolBar.ImageList = imageL
然后将ImageList控件中的图像赋给工具按钮的ImageIndex属性。
newToolBarButton.ImageIndex = 0; openToolBarButton.ImageIndex = 1; saveToolBarButton.ImageIndex = 2; printToolBarButton.ImageIndex = 3; 象菜单项一样,现在必须把工具按钮加入到工具条中。
toolBar.Buttons.Add(separatorToolBarButton); toolBar.Buttons.Add(newToolBarButton); toolBar.Buttons.Add(openToolBarButton); toolBar.Buttons.Add(saveToolBarButton); toolBar.Buttons.Add(separatorToolBarButton); toolBar.Buttons.Add(printToolBarButton); 最后将工具条加入到窗体中。
this.Controls.Add(toolBar); 添加状态条 状态条由System.Windows.Forms.StatusBar描述,它提供了定制控件的外观的属性,状态条由StatusBarPanel对象组成,在我们的模板中状态条有两个嵌套板:
StatusBar statusBar = new StatusBar(); StatusBarPanel statusBarPanel1 = new StatusBarPanel(); StatusBarPanel statusBarPanel2 = new StatusBarPanel(); 状态条和状态跳上的嵌套板由下面的代码设置:
statusBarPanel1.BorderStyle = StatusBarPanelBorderStyle.S statusBarPanel1.Text = "Press F1 for Help"; statusBarPanel1.AutoSize = StatusBarPanelAutoSize.S statusBarPanel2.BorderStyle = StatusBarPanelBorderStyle.R statusBarPanel2.ToolTipText = System.DateTime.Now.ToShortTimeString(); statusBarPanel2.Text = System.DateTime.Today.ToLongDateString(); statusBarPanel2.AutoSize = StatusBarPanelAutoSize.C statusBar.ShowPanels = statusBar.Panels.Add(statusBarPanel1); statusBar.Panels.Add(statusBarPanel2); 同样我们需要将状态条添加到窗体中:
this.Controls.Add(statusBar); 事件处理器 在windows程序设计中添加事件处理器是最重要的任务。事件处理器保证了程序与用户交互,同时完成其他重要的功能。在c#中你可以给控件和菜单事件添加事件处理器以俘获你想处理的事件,下面的代码给Button控件的click事件设计了一个事件处理器:
button.Click += new System.EventHandler(this.button_Click); button_Click事件处理器必须被处理: private void button_Click(Object sender, System.EventArgs e) { MessageBox.Show("Thank you.", "The Event Information"); }
MenuItem 对象在实例化的同时可以给赋以一个事件处理器:
fileNewMenuItem = new MenuItem("&New", new System.EventHandler(this.fileNewMenuItem_Click), Shortcut.CtrlN); fileOpenMenuItem = new MenuItem("&Open", new System.EventHandler(this.fileOpenMenuItem_Click), Shortcut.CtrlO); fileSaveMenuItem = new MenuItem("&Save", new System.EventHandler(this.fileSaveMenuItem_Click), Shortcut.CtrlS); fileSaveAsMenuItem = new MenuItem("Save &As", new System.EventHandler(this.fileSaveAsMenuItem_Click)); fileMenuWithSubmenu = new MenuItem("&With Submenu"); submenuMenuItem = new MenuItem("Su&bmenu", new System.EventHandler(this.submenuMenuItem_Click)); fileExitMenuItem = new MenuItem("E&xit", new System.EventHandler(this.fileExitMenuItem_Click)); 你不能给工具按钮指派一个事件处理器,但可以给工具条指派一个事件处理器:
toolBar.ButtonClick += new ToolBarButtonClickEventHandler(this.toolBar_ButtonClick); protected void toolBar_ButtonClick(Object sender, ToolBarButtonClickEventArgs e) { // Evaluate the Button property to determine which button was clicked. switch (toolBar.Buttons.IndexOf(e.Button)) { case 1: MessageBox.Show("Second button.", "The Event Information");
case 2: MessageBox.Show("third button", "The Event Information");
case 3: MessageBox.Show("fourth button.", "The Event Information");
例子中也给窗体的close事件设计了一个事件处理器,通过重载OnClosing方法你可以接收用户点击窗体的X按钮,这样你可以取消关闭事件:
protected override void OnClosing(CancelEventArgs e) { MessageBox.Show("Exit now.", "The Event Information"); }
现在我们的模板就完成了,你可以使用他开始你的WINDOWS应用程序设计。&#p#
附录 Listing 1. C# Windows 应用程序模板
/* to compile this source file, type csc MyWinApp.cs */ using S using System.Windows.F using System.D using System.IO; ponentM public class MyWinApp: Form { Label label = new Label(); Button button = new Button(); TreeView tree = new TreeView(); ImageList imageList = new ImageList(); static String imageFolder = "Images" + Path.DirectorySeparatorChar.ToString(); // -------------- Images declarations ------------------------------------ Image newFileImage = new Bitmap(imageFolder + "newFile.bmp"); Image openFileImage = new Bitmap(imageFolder + "openFile.gif"); Image saveFileImage = new Bitmap(imageFolder + "saveFile.bmp"); Image printImage = new Bitmap(imageFolder + "print.gif"); // -------------- End of Images declaration ------------------------------------ // -------------- menu ------------------------------------ MainMenu mainMenu = new MainMenu(); MenuItem fileMenuItem = new MenuItem(); MenuItem fileNewMenuI MenuItem fileOpenMenuI MenuItem fileSaveMenuI MenuItem fileSaveAsMenuI MenuItem fileMenuWithS MenuItem submenuMenuI MenuItem fileExitMenuI // -------------- End of menu ------------------------------------ // -------------- Toolbar ------------------------------------ ToolBar toolBar = new ToolBar(); ToolBarButton separatorToolBarButton = new ToolBarButton(); ToolBarButton newToolBarButton = new ToolBarButton(); ToolBarButton openToolBarButton = new ToolBarButton(); ToolBarButton saveToolBarButton = new ToolBarButton(); ToolBarButton printToolBarButton = new ToolBarButton(); // -------------- End of Toolbar ------------------------------------ // -------------- StatusBar ------------------------------------ StatusBar statusBar = new StatusBar(); StatusBarPanel statusBarPanel1 = new StatusBarPanel(); StatusBarPanel statusBarPanel2 = new StatusBarPanel(); // -------------- End of StatusBar ------------------------------------ public MyWinApp() { InitializeComponent(); } private void InitializeComponent() { this.Text = "My Windows Application"; this.Icon = new Icon(imageFolder + "applicationLogo.ico"); this.Width = 400; this.Height = 300; this.StartPosition = FormStartPosition.CenterS imageList.Images.Add(newFileImage); imageList.Images.Add(openFileImage); imageList.Images.Add(saveFileImage); imageList.Images.Add(printImage); // menu fileMenuItem.Text = "&File"; // the following constructor is the same as: // menuItem fileNewMenuItem = new MenuItem(); // fileNewMenuItem.Text = "&New"; // fileNewMenuItem.Shortcut = Shortcut.CtrlN; // fileNewMenuItem.Click += new System.EventHandler(this.fileNewMenuItem_Click); fileNewMenuItem = new MenuItem("&New", new System.EventHandler(this.fileNewMenuItem_Click), Shortcut.CtrlN); fileOpenMenuItem = new MenuItem("&Open", new System.EventHandler(this.fileOpenMenuItem_Click), Shortcut.CtrlO); fileSaveMenuItem = new MenuItem("&Save", new System.EventHandler(this.fileSaveMenuItem_Click), Shortcut.CtrlS); fileSaveAsMenuItem = new MenuItem("Save &As", new System.EventHandler(this.fileSaveAsMenuItem_Click)); fileMenuWithSubmenu = new MenuItem("&With Submenu"); submenuMenuItem = new MenuItem("Su&bmenu", new System.EventHandler(this.submenuMenuItem_Click)); fileExitMenuItem = new MenuItem("E&xit", new System.EventHandler(this.fileExitMenuItem_Click)); mainMenu.MenuItems.Add(fileMenuItem); fileOpenMenuItem.Checked = fileMenuItem.MenuItems.Add(fileNewMenuItem); fileMenuItem.MenuItems.Add(fileOpenMenuItem); fileMenuItem.MenuItems.Add(fileSaveMenuItem); fileMenuItem.MenuItems.Add(fileSaveAsMenuItem); fileMenuItem.MenuItems.Add(fileMenuWithSubmenu); fileMenuWithSubmenu.MenuItems.Add(submenuMenuItem); fileMenuItem.MenuItems.Add("-"); // add a separator fileMenuItem.MenuItems.Add(fileExitMenuItem); toolBar.Appearance = ToolBarAppearance.N //toolBar.Appearance = ToolBarAppearance.F toolBar.ImageList = imageL toolBar.ButtonSize = new Size(14, 6); separatorToolBarButton.Style = ToolBarButtonStyle.S newToolBarButton.ToolTipText = "New Document"; newToolBarButton.ImageIndex = 0; openToolBarButton.ToolTipText = "Open Document"; openToolBarButton.ImageIndex = 1; saveToolBarButton.ToolTipText = "Save"; saveToolBarButton.ImageIndex = 2; printToolBarButton.ToolTipText = "Print"; printToolBarButton.ImageIndex = 3; toolBar.ButtonClick += new ToolBarButtonClickEventHandler(this.toolBar_ButtonClick); toolBar.Buttons.Add(separatorToolBarButton); toolBar.Buttons.Add(newToolBarButton); toolBar.Buttons.Add(openToolBarButton); toolBar.Buttons.Add(saveToolBarButton); toolBar.Buttons.Add(separatorToolBarButton); toolBar.Buttons.Add(printToolBarButton); tree.Top = 40; tree.Left = 20; tree.Width = 100; tree.Height = 100; label.Location = new Point(220, 40); label.Size = new Size(160, 30); label.Text = "Yes, click the button"; button.Location = new Point(220, 80); button.Size = new Size(100, 30); button.Text = "Click this"; button.Click += new System.EventHandler(this.button_Click); statusBarPanel1.BorderStyle = StatusBarPanelBorderStyle.S statusBarPanel1.Text = "Press F1 for Help"; statusBarPanel1.AutoSize = StatusBarPanelAutoSize.S statusBarPanel2.BorderStyle = StatusBarPanelBorderStyle.R statusBarPanel2.ToolTipText = System.DateTime.Now.ToShortTimeString(); statusBarPanel2.Text = System.DateTime.Today.ToLongDateString(); statusBarPanel2.AutoSize = StatusBarPanelAutoSize.C statusBar.ShowPanels = statusBar.Panels.Add(statusBarPanel1); statusBar.Panels.Add(statusBarPanel2); this.Menu = mainM this.Controls.Add(toolBar); this.Controls.Add(tree); this.Controls.Add(label); this.Controls.Add(button); this.Controls.Add(statusBar); } // -------------- Event Handlers -------------------------- private void fileNewMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the File -- New menu.", "The Event Information"); } private void fileOpenMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the File -- Open menu.", "The Event Information"); } private void fileSaveMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the File -- Save menu.", "The Event Information"); } private void fileSaveAsMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the File -- Save As menu.", "The Event Information"); } private void fileExitMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the File -- Exit As menu.", "The Event Information"); } private void submenuMenuItem_Click(Object sender, EventArgs e) { MessageBox.Show("You clicked the submenu.", "The Event Information"); } protected void toolBar_ButtonClick(Object sender, ToolBarButtonClickEventArgs e) { // Evaluate the Button property to determine which button was clicked. switch (toolBar.Buttons.IndexOf(e.Button)) { case 1: MessageBox.Show("Second button.", "The Event Information");
case 2: MessageBox.Show("third button", "The Event Information");
case 3: MessageBox.Show("fourth button.", "The Event Information");
} } protected override void OnClosing(CancelEventArgs e) { MessageBox.Show("Exit now.", "The Event Information"); } private void button_Click(Object sender, System.EventArgs e) { MessageBox.Show("Thank you.", "The Event Information"); } // -------------- End of Event Handlers ------------------- public static void Main() { MyWinApp form = new MyWinApp(); Application.Run(form); } }怎样设置C#应用程序占用CPU的个数?
我有一个C#小程序开了十几个线程,都在运行很占CPU的操作.
现在这个小程序如果放在双核的电脑上,两个核都用满100%
放在4核的电脑上,4个核就都用满
放在有两个4核CPU的电脑上,那个8个核都用满.
总之就是无论电脑有几个核,全部占满,总CPU使用率都是100%.
现在我希望它只占用1-2个CPU,这样放在4核电脑上运行,就只会占用50%的CPU,不至于把电脑卡死.
我记得以前看过可以在VS里进行设置,指定程序占用CPU个数的.但现在找不到了.
有人知道怎么设置吗
该回复于 11:05:55被版主删除
这个想法比较牛叉,估计这个是操作系统的活吧
既然是"都在运行很占CPU的操作",那么根据当前CPU个数,开操作线程不就可以了?
Environment.ProcessorCount
里面加点sleep吧
可以考虑优化你的程序了,还小程序啊
先优化下代码吧,看看是不是有运行上的缺陷……小程序&&&100%……
肯定是你的程序有问题啊。
1&希望能腾出CPU给其他程序的话,可以尝试设置线程优先级
Thread.CurrentThread.Priority&=&ThreadPriority.L&
2&程序应尽快完成任务,限制CPU与此目的违背,若没有别的需要CPU资源,没必要限制(也就是第一点了)
代码优化上,比如你用一个while&true循环做轮询,1秒一次就够了,就应该在每次轮询后sleep一下,这就是最该考虑的优化点。
3&还是要限制CPU的话,看看&
引用&9&楼&cosmo_sei&的回复:1&希望能腾出CPU给其他程序的话,可以尝试设置线程优先级
Thread.CurrentThread.Priority&=&ThreadPriority.L&
2&程序应尽快完成任务,限制CPU与此目的违背,若没有别的需要CPU资源,没必要限制(也就是第一点了)
代码优化上,比如你用一个while&true循环做轮询,1秒一次就够了,就应该在每次轮询后sleep一下,这就是……
现在我就是想尽快地运行我需要的东西,但不是100%都用来运行它,留那么少量的CPU去做其他事,不让系统卡死.
回复
即使是一小步也想与你分享

我要回帖

更多关于 蓝色警戒分辨率 的文章

 

随机推荐