PK yЗL ! 15-XX-AsyncProcessTable-WinForms/PK {qABУy@ЮЛ Л + 15-XX-AsyncProcessTable-WinForms/App.configяЛП
PK WИHЕж~ѓ ѓ + 15-XX-AsyncProcessTable-WinForms/AppForm.csяЛПusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Threading;
namespace AsyncProcessTable_WinForms {
public partial class AppForm : Form {
private static TaskScheduler uiTaskScheduler = null;
private static AppForm instance = null;
public AppForm() {
Debug.Assert(instance == null);
instance = this;
uiTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
InitializeComponent();
PrintContextInfo("AppForm constructor");
}
private async void processTableButton_Click(object sender, EventArgs e) {
eventLogListBox.Items.Clear();
PrintContextInfo("processTableButton_Click starts");
processTableButton.Enabled = false;
using (var sr = new StreamReader(new FileStream("Zelenina.txt", FileMode.Open, FileAccess.Read, FileShare.Read, 16, true))) {
Debug.WriteLine("Reader's stream: IsAsync == {0}", (sr.BaseStream as FileStream).IsAsync);
using (var sw = new StreamWriter(new FileStream("Vystup.txt", FileMode.Create, FileAccess.Write, FileShare.Read, 16, true))) {
Debug.WriteLine("Writer's stream: IsAsync == {0}", (sw.BaseStream as FileStream).IsAsync);
if (((Button) sender).Tag.Equals("1")) {
await Task.Factory.StartNew(() => {
ProcessFile(sr, sw).Wait();
});
} else if (((Button) sender).Tag.Equals("2")) {
//
} else if (((Button) sender).Tag.Equals("3")) {
await ProcessFile(sr, sw);
} else if (((Button) sender).Tag.Equals("4")) {
await ProcessFile(sr, sw).ConfigureAwait(continueOnCapturedContext: true);
} else if (((Button) sender).Tag.Equals("5")) {
await ProcessFile(sr, sw).ConfigureAwait(continueOnCapturedContext: false);
}
}
}
processTableButton.Enabled = true;
PrintContextInfo("processTableButton_Click ends");
}
static readonly char[] Separators = { ' ', '\t' };
static async Task ProcessFile(TextReader input, TextWriter output) {
PrintContextInfo("т ProcessFile starts");
var readLineTask = input.ReadLineAsync();
Task writeLineTask = null;
string line;
while ((line = await readLineTask) != null) {
readLineTask = input.ReadLineAsync();
string[] words = line.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
PrintContextInfo("т т ProcessFile loop iteration");
await Task.Delay(100);
if (writeLineTask != null) {
await writeLineTask;
}
writeLineTask = output.WriteLineAsync(words[0]);
}
PrintContextInfo("т ProcessFile ends");
}
static void PrintContextInfo(string callerInfo = null) {
int callingThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
string callingTaskId = Task.CurrentId == null ? "тnullт" : Task.CurrentId.Value.ToString();
string callingSynchroContext = System.Threading.SynchronizationContext.Current == null ? "тnullт" : System.Threading.SynchronizationContext.Current.GetType().Name;
new Task(() => {
instance.eventLogListBox.Items.Add(
string.Format("ThreadId: {0} ({4}), TaskId: {1} ({5}), SynchroContext: {2} ({6}) {3}",
callingThreadId, callingTaskId, callingSynchroContext, callerInfo == null ? "" : "in " + callerInfo,
System.Threading.Thread.CurrentThread.ManagedThreadId,
Task.CurrentId == null ? "тnullт" : Task.CurrentId.Value.ToString(),
System.Threading.SynchronizationContext.Current == null ? "тnullт" : System.Threading.SynchronizationContext.Current.GetType().Name
)
);
}).Start(uiTaskScheduler);
}
}
}
PK ZVИHЛ%w. . 4 15-XX-AsyncProcessTable-WinForms/AppForm.Designer.csяЛПnamespace AsyncProcessTable_WinForms {
partial class AppForm {
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing) {
if (disposing && (components != null)) {
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent() {
this.processTableButton = new System.Windows.Forms.Button();
this.eventLogListBox = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// processTableButton
//
this.processTableButton.Location = new System.Drawing.Point(12, 12);
this.processTableButton.Name = "processTableButton";
this.processTableButton.Size = new System.Drawing.Size(120, 23);
this.processTableButton.TabIndex = 0;
this.processTableButton.Tag = "1";
this.processTableButton.Text = "Process table v1";
this.processTableButton.UseVisualStyleBackColor = true;
this.processTableButton.Click += new System.EventHandler(this.processTableButton_Click);
//
// eventLogListBox
//
this.eventLogListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.eventLogListBox.FormattingEnabled = true;
this.eventLogListBox.IntegralHeight = false;
this.eventLogListBox.Location = new System.Drawing.Point(138, 12);
this.eventLogListBox.Name = "eventLogListBox";
this.eventLogListBox.Size = new System.Drawing.Size(572, 448);
this.eventLogListBox.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 41);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(120, 23);
this.button1.TabIndex = 2;
this.button1.Tag = "2";
this.button1.Text = "Process table v2";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.processTableButton_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(12, 70);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(120, 23);
this.button2.TabIndex = 3;
this.button2.Tag = "3";
this.button2.Text = "Process table v3";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.processTableButton_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(12, 99);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(120, 23);
this.button3.TabIndex = 4;
this.button3.Tag = "4";
this.button3.Text = "Process table v4";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.processTableButton_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(12, 128);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(120, 23);
this.button4.TabIndex = 5;
this.button4.Tag = "5";
this.button4.Text = "Process table v5";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.processTableButton_Click);
//
// AppForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(722, 472);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.eventLogListBox);
this.Controls.Add(this.processTableButton);
this.Name = "AppForm";
this.Text = "AsyncProcessTable";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button processTableButton;
private System.Windows.Forms.ListBox eventLogListBox;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
}
}
PK ZVИHО|EIЙ Й - 15-XX-AsyncProcessTable-WinForms/AppForm.resxяЛП
text/microsoft-resx
2.0
System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
PK аqABМЦ B 15-XX-AsyncProcessTable-WinForms/AsyncProcessTable-WinForms.csprojяЛП
Debug
AnyCPU
{74EFE280-3028-4537-88CE-F9C3AD64316C}
WinExe
Properties
AsyncProcessTable_WinForms
AsyncProcessTable-WinForms
v4.5
512
AnyCPU
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
AnyCPU
pdbonly
true
bin\Release\
TRACE
prompt
4
Form
AppForm.cs
AppForm.cs
ResXFileCodeGenerator
Resources.Designer.cs
Designer
True
Resources.resx
SettingsSingleFileGenerator
Settings.Designer.cs
True
Settings.settings
True
PK }qABXE~ќ ? 15-XX-AsyncProcessTable-WinForms/AsyncProcessTable-WinForms.slnяЛП
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AsyncProcessTable-WinForms", "AsyncProcessTable-WinForms.csproj", "{74EFE280-3028-4537-88CE-F9C3AD64316C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{74EFE280-3028-4537-88CE-F9C3AD64316C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74EFE280-3028-4537-88CE-F9C3AD64316C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74EFE280-3028-4537-88CE-F9C3AD64316C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74EFE280-3028-4537-88CE-F9C3AD64316C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
PK SDЙ5 Ђ Ђ C 15-XX-AsyncProcessTable-WinForms/AsyncProcessTable-WinForms.v11.suoаЯрЁБс > ўџ ўџџџ џџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџR o o t E n t r y џџџџџџџџ нW^Я P r o j I n f o E x џџџџџџџџџџџџ { T a s k L i s t U s e r T a s k s $ " џџџџџџџџ r W i n d o w M a n a g e r . P i n n e d F r a m e s 6 џџџџ q §џџџџџџџџџџџџџџџўџџџџџџџ
ўџџџ џџџџўџџџџџџџџџџџџџџџџџџџџџџџџџџџ џџџџA џџџџџџџџ4 џџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџ5 6 7 8 9 : ; <