
您好。
很遗憾!联想S868t手机无手机后台程序数量限制设置,建议您可使用一键清理软件实时清理后台。请了解。
欢迎您随时与我们联系或访问联想乐问吧(>
见下面代码
using System;using SystemCollectionsGeneric;
using SystemText;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double [] myArray = new double[10];
ConsoleWriteLine("请输入十个数");
for (int i = 0; i < 10; i++)
{
myArray[i] = ConvertToDouble(ConsoleReadLine());
}
ArraySort(myArray);
ConsoleWriteLine("最大数数为"+myArray[9]ToString());
ConsoleWriteLine("第二最大数数为" + myArray[8]ToString());
ConsoleReadLine();
}
}
}
说实话,关于进度条的解决方案很多,我暂且假定你在做Winform程序开发。
如果你使用的StatusBar中的进度条的话,你可以不考虑多线程更新UI的问题,因为它本身已经在内部实现了外部线程更新UI控件的逻辑。 但是如果你使用普通的Progressbar控件,那你就得自己处理这部分逻辑,因为控件只能在其所在的UI中更新,如果你想在其它线程中更新那你得用控件上的BeginInvoke方法, 当然还有其它的解决方案。
方案1:
using System;using SystemDrawing;
using SystemIO;
using SystemWindowsForms;
using SystemThreading;
using SystemThreadingTasks;
namespace AskAnswers
{
public class ShowProgressStatus : Form
{
[STAThread]
static void Main()
{
ApplicationRun(new ShowProgressStatus());
}
public ShowProgressStatus()
{
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with an editor
/// </summary>
private void InitializeComponent()
{
thiscomponents = new SystemComponentModelContainer();
thislabel1 = new SystemWindowsFormsLabel();
thisprogressBar1 = new SystemWindowsFormsProgressBar();
thisbtnProcess = new SystemWindowsFormsButton();
thistextBox1 = new SystemWindowsFormsTextBox();
//@design thisTrayHeight = 0;
//@design thisTrayLargeIcon = false;
//@design thisTrayAutoArrange = true;
label1Location = new SystemDrawingPoint(32, 40);
label1Text = "Progress Value";
label1Size = new SystemDrawingSize(88, 24);
label1TabIndex = 2;
progressBar1Maximum = 10;
progressBar1Location = new SystemDrawingPoint(8, 312);
progressBar1Minimum = 0;
progressBar1TabIndex = 0;
progressBar1Value = 0;
//We have calculated the excat size which will result in only 20 boxes to be drawn
progressBar1Size = new SystemDrawingSize(520, 40);
progressBar1Step = 1;
btnProcessLocation = new SystemDrawingPoint(152, 168);
btnProcessSize = new SystemDrawingSize(144, 48);
btnProcessTabIndex = 1;
btnProcessText = "Process";
btnProcessClick += new SystemEventHandler(btnProcess_Click);
textBox1Location = new SystemDrawingPoint(136, 40);
textBox1Text = "0";
textBox1TabIndex = 3;
textBox1Size = new SystemDrawingSize(184, 20);
thisText = "Display Progress Status";
thisAutoScaleBaseSize = new SystemDrawingSize(5, 13);
thisClientSize = new SystemDrawingSize(616, 393);
thisStartPosition = FormStartPositionCenterScreen;
thisControlsAdd(textBox1);
thisControlsAdd(label1);
thisControlsAdd(btnProcess);
thisControlsAdd(progressBar1);
}
void btnProcess_Click(object sender, EventArgs e)
{
if (isProcessRunning)
{
MessageBoxShow("A process is already running");
return;
}
string[] files = DirectoryGetFiles(@"c:\", "");
var filesCount = filesLength;
progressBar1Maximum = filesCount;
ThreadSleep(50);
Thread backgroundThread = new Thread(
new ThreadStart(() =>
{
isProcessRunning = true;
for (int n = 0; n < filesCount; n++ )
{
// 模拟拷贝文件过程
ThreadSleep(100);
ConsoleWriteLine(files[n]);
progressBar1BeginInvoke(
new Action(() =>
{
progressBar1Value = n + 1;
}
));
}
MessageBoxShow("Thread completed!");
progressBar1BeginInvoke(
new Action(() =>
{
progressBar1Value = 0;
}
));
isProcessRunning = false;
}
));
backgroundThreadStart();
}
private SystemWindowsFormsButton btnProcess;
private SystemComponentModelContainer components;
private SystemWindowsFormsTextBox textBox1;
private SystemWindowsFormsLabel label1;
private SystemWindowsFormsProgressBar progressBar1;
private bool isProcessRunning;
}
}
方案2: 利用线程池(TaskStartNew())
你只要把btnProcess_Click中的代码替换为下面的代码即可:
void btnProcess_Click(object sender, EventArgs e){
if (isProcessRunning)
{
MessageBoxShow("A process is already running");
return;
}
Task<string[]>FactoryStartNew(() => {
isProcessRunning = true;
return DirectoryGetFiles(@"C:\", "");
})
ContinueWith(files => {
string[] filesResult = filesResult;
progressBar1Maximum = filesResultLength;
ConsoleWriteLine("The Maximum of Progress Bar " + progressBar1Maximum);
return filesResult;
})
ContinueWith(files => {
string[] filesResult = filesResult;
ConsoleWriteLine("The files count " + filesResultLength);
for (int n = 0; n < filesResultLength; n++ )
{
// 模拟拷贝文件过程
ThreadSleep(100);
ConsoleWriteLine(filesResult[n]);
progressBar1Value = n + 1;
}
})
ContinueWith(files => {
MessageBoxShow("Thread completed!");
progressBar1BeginInvoke(
new Action(() =>
{
progressBar1Value = 0;
}
));
isProcessRunning = false;
});
}
当然,你也可以通过BackgroundWorker来做,可能更简单一点儿,原理相同,你可以搜索一下相关方案。
注意,我只是通过一个ThreadSleep(100)来模拟你Copy文件的逻辑。
以上就是关于怎么限制安卓手机后台程序数量联想s868t全部的内容,包括:怎么限制安卓手机后台程序数量联想s868t、联想S696如何限制后台运行程序数量、用c#设计一个控制台程序,要求用户输入10个数,并输出其中最大的数和第二大的数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)