Windows 7

, , , .

 
» C# »

7. C#.

 
, , , , , .

, , , ( ).

using :

using System.Threading;
using System.Threading.Tasks;
using System.Timers;

, , :

1. System.Threading System.Threading.Tasks ;
2. System.Timers . .

, .

BackgroundWorker bgwSchet. WorkerReportProgress = true.

3 :

1. DoWork bgwSchetDoWork
2. ProgressChanged bgwSchetProgressCanged
3. RunWorkerCompleted bgwSchetRunWorkerCompleted

frmOS7ru.cs .

ConsoleKeyEnter(string strKeys) :

case "": ConsoleKeyEnter_Potok(strKeys); break;


:

else if (strKeys == "" || strKeys == "_")
{
arrstrConsoleVvod_Gpr[0] = "";
txtbConsole.Text = " " + NewLine;
}

ConsoleKeyEnter_Potok(strKeys):

private void ConsoleKeyEnter_Potok(string strKeys)//
{
if (arrstrConsoleVvod_Gpr[1] == "")
ConsoleKeyEnter_Potok_Sravnit(strKeys);
else
if (strKeys == "" || strKeys == "_?")
{
txtbConsole.Text = " " + NewLine;
for (int i = 0; i < arrstrVoprosPotok_Gpr.Length; i++) txtbConsole.Text += NewLine + arrstrVoprosPotok_Gpr[i];
}
else if (strKeys == "" || strKeys == "_")
{
txtbConsole.Text = " " + NewLine;
for (int i = 0; i < arrstrConsoleVvod_Gpr[i].Length; i++) arrstrConsoleVvod_Gpr[i] = "";
}
else if (strKeys == "" || strKeys == "_")
{
arrstrConsoleVvod_Gpr[1] = "";
txtbConsole.Text = " " + NewLine;
}
else if (strKeys == "" || strKeys == "_")
{
txtbConsole.Text = " " + NewLine;
for (int i = 0; i < arrstrConsoleVvod_Gpr[i].Length; i++) arrstrConsoleVvod_Gpr[i] = "";
}
else
{
txtbConsole.Text += NewLine + " \"" + strKeys + "\"" + NewLine +
" . \"\"";
}
}

ConsoleKeyEnter_Potok_Sravnit:

private void ConsoleKeyEnter_Potok_Sravnit(string strKeys)//
{
if (strKeys == "" || strKeys == "_?")
{
txtbConsole.Text = " " + NewLine;
for (int i = 0; i < arrstrVoprosPotokSravnit_Gpr.Length; i++) txtbConsole.Text += NewLine + arrstrVoprosPotokSravnit_Gpr[i];
}
else if (strKeys == "" || strKeys == "_")
{
txtbConsole.Text = " " + NewLine;
for (int i = 0; i < arrstrConsoleVvod_Gpr[i].Length; i++) arrstrConsoleVvod_Gpr[i] = "";
}
else if (strKeys == "" || strKeys == "_")
{
txtbConsole.Text = " " + NewLine;
for (int i = 0; i < arrstrConsoleVvod_Gpr[i].Length; i++) arrstrConsoleVvod_Gpr[i] = "";
}
else
{
try
{
if (txtbConsoleMain.Text.Trim().Length > 0)
iChisloPotokov_Gpr = Convert.ToInt16(txtbConsoleMain.Text.Trim());
tmrSchet.Enabled = true;//
arriVrema_Gpr[0] = arriVrema_Gpr[1] = 0;// 蠠
bgwSchet.RunWorkerAsync();// BackgroundWorker
}
catch
{
txtbConsole.Text = NewLine + " \"" + strKeys + "\"" + NewLine +
" . \"\""+NewLine +
" .";
}
}
}

, :

private void bgwSchetDoWork(object sender, DoWorkEventArgs e)// , bgwSchetRunWorker
{
ProgressChangedEventArgs PCEA = new ProgressChangedEventArgs(0, "");//
bgwSchetProgressCanged(sender, PCEA);// ProgressCanged
bSchetFlag_Gpr = true;
tmrSchet.Start();//
int n = 1000000;
double[] arrd = new double[iChisloPotokov_Gpr];
for (int i = 0; i < iChisloPotokov_Gpr; i++)
{
arrd[i] = Schet(n, i, arrd[i]);
double dThis=i;
dThis /= iChisloPotokov_Gpr;
iProcent_Gpr = (int)(dThis * 50);
}
PCEA =new ProgressChangedEventArgs(50, "");//
bgwSchetProgressCanged(sender, PCEA);// ProgressCanged
bSchetFlag_Gpr = false;
bSchetFlag2_Gpr = true;
double[] arrd1 = new double[iChisloPotokov_Gpr];
while (!Parallel.For(0, iChisloPotokov_Gpr, delegate(int i)
{
arrd1[i] = Schet(n, i, arrd1[i]);
}).IsCompleted) { };
iProcent_Gpr = 100;
bSchetFlag2_Gpr = false;
}

:
for (int i = 0; i < iChisloPotokov_Gpr; i++)
{
arrd[i] = Schet(n, i, arrd[i]);
double dThis=i;
dThis /= iChisloPotokov_Gpr;
iProcent_Gpr = (int)(dThis * 50);
}
- , BackgroundWorker. : iProcent_Gpr = (int)( (i/iChisloPotokov_Gpr )* 50); iProcent_Gpr . .

, . .

, , :

private int iChisloPotokov_Gpr = 100;//
private int[] arriVrema_Gpr = { 0, 0 };//
private bool bSchetFlag_Gpr = false;//
private bool bSchetFlag2_Gpr = false;// 2
private int iProcent_Gpr = 0;//

:

while (!Parallel.For(0, iChisloPotokov_Gpr, delegate(int i)
{
arrd1[i] = Schet(n, i, arrd1[i]);
}).IsCompleted) { };

Parallel.For . ( while, , IsCompleted).

(Label) , , . ProgressBar. prgbSchet, .

bgwSchetProgressCanged :

iProcent_Gpr = e.ProgressPercentage;


, , , BackgroundWorker:

tmrSchet.Stop();//
tmrSchet.Enabled = false;//
txtbConsole.Text = "\t 1: " + arriVrema_Gpr[0] + NewLine + "\t 2: " + arriVrema_Gpr[1];
txtbConsole.Text += NewLine + " " + NewLine;
prgbSchet.Value = iProcent_Gpr;//, ProgressBar

tmrSchet Tick tmrSchetTick:

private void tmrSchetTick(object sender, EventArgs e) //
{
Monitor.Enter(bgwSchet);// bgwSchet
if (bSchetFlag_Gpr)
{
arriVrema_Gpr[0]++;
txtbConsole.Text = "\t 1 (" + (arriVrema_Gpr[0] * 0.1) + " )";
prgbSchet.Value = iProcent_Gpr;
txtbConsole.Invalidate();
prgbSchet.Invalidate();
}
else
{
arriVrema_Gpr[1]++;
txtbConsole.Text = "\t 2 (" + (arriVrema_Gpr[1]*0.1) + " )";
txtbConsole.Invalidate();
prgbSchet.Value = iProcent_Gpr;
prgbSchet.Invalidate();
}
Monitor.Exit(bgwSchet);// bgwSchet
}

: ? : , : , .

: .

, , Schet:

private double Schet(int iN, int i,double d)//
{
for (int j = 0; j < iN; j++) d += ((j * i )/ iN);
return d;
}

consoleKeyDown:

private void consoleKeyDown(object sender, KeyEventArgs e)//
{
switch (e.KeyCode)
{
case Keys.Enter:// "Enter"
{
if (bSchetFlag_Gpr || bSchetFlag2_Gpr)
{
txtbConsoleMain.Text = "";
MessageBox.Show(" ");
}
else
{
ConsoleKeyEnter(txtbConsoleMain.Text.Trim());
txtbConsoleMain.Text = "";
ConsoleAutoCompleteSource(arrstrConsoleVvod_Gpr);
}
} break;
case Keys.Space:// "Space"
{
if (bSchetFlag_Gpr || bSchetFlag2_Gpr)
{
txtbConsoleMain.Text = "";
MessageBox.Show(" ");
}
else
{
ConsoleKeyEnter(txtbConsoleMain.Text.Trim());
txtbConsoleMain.Text = "";
ConsoleAutoCompleteSource(arrstrConsoleVvod_Gpr);
}
} break;
default: break;
}
}

, , : MessageBox.Show(" ");.

ConsoleAutoCompleteSource , . .

, :

private string[] arrstrVopros_Gpr = { "", "", "", "","", "" }; //


:

private string[] arrstrVoprosPotok_Gpr = { "", "", "", "" }; //
private string[] arrstrVoprosPotokSravnit_Gpr = { "", "", "" }; //

, (. 1):

 7.      C#.

. 1.


, , , . , . .


: .










DiamondTigeR

 7.      C#.



: d.tiger. : 23-10-2012, 20:57

: 3702

:

, OS-7.RU, - .







 (: 0)
(0)
 
 

, ,

Windows 7

-

Windows 7

Windows 7