commit d098893fde79328aef60e99699153935d0dc77f0 Author: juanjo Date: Fri Oct 27 11:54:06 2023 +0200 CSharp 01.Procesos Código fuente diff --git a/01-IntroProcesos/01-IntroProcesos.csproj b/01-IntroProcesos/01-IntroProcesos.csproj new file mode 100644 index 0000000..89ece7e --- /dev/null +++ b/01-IntroProcesos/01-IntroProcesos.csproj @@ -0,0 +1,83 @@ + + + + + Debug + AnyCPU + {AFE3B6BE-A35E-466E-AFFE-1BE73DE7FCAC} + WinExe + _01_IntroProcesos + 01-IntroProcesos + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/01-IntroProcesos/App.config b/01-IntroProcesos/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/01-IntroProcesos/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/01-IntroProcesos/Form1.Designer.cs b/01-IntroProcesos/Form1.Designer.cs new file mode 100644 index 0000000..f39a5b0 --- /dev/null +++ b/01-IntroProcesos/Form1.Designer.cs @@ -0,0 +1,202 @@ +namespace _01_IntroProcesos +{ + partial class Form1 + { + /// + /// Variable del diseñador necesaria. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Limpiar los recursos que se estén usando. + /// + /// true si los recursos administrados se deben desechar; false en caso contrario. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Código generado por el Diseñador de Windows Forms + + /// + /// Método necesario para admitir el Diseñador. No se puede modificar + /// el contenido de este método con el editor de código. + /// + private void InitializeComponent() + { + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.button4 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.button6 = new System.Windows.Forms.Button(); + this.button7 = new System.Windows.Forms.Button(); + this.button8 = new System.Windows.Forms.Button(); + this.button9 = new System.Windows.Forms.Button(); + this.button10 = new System.Windows.Forms.Button(); + this.button11 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(23, 156); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(201, 54); + this.button1.TabIndex = 0; + this.button1.Text = "iniciar Proceso"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.Button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(23, 231); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(201, 52); + this.button2.TabIndex = 1; + this.button2.Text = "eliminar Proceso"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.Button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(255, 156); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(147, 54); + this.button3.TabIndex = 2; + this.button3.Text = "listar Procesos"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.Button3_Click); + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(451, 156); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(224, 21); + this.comboBox1.TabIndex = 3; + // + // button4 + // + this.button4.Location = new System.Drawing.Point(255, 231); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(147, 52); + this.button4.TabIndex = 4; + this.button4.Text = "listar Chrome"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.Button4_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(255, 304); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(147, 52); + this.button5.TabIndex = 5; + this.button5.Text = "matar Chrome"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.Button5_Click); + // + // button6 + // + this.button6.Location = new System.Drawing.Point(23, 12); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(201, 54); + this.button6.TabIndex = 6; + this.button6.Text = "inicio Proceso simple"; + this.button6.UseVisualStyleBackColor = true; + this.button6.Click += new System.EventHandler(this.button6_Click); + // + // button7 + // + this.button7.Location = new System.Drawing.Point(244, 12); + this.button7.Name = "button7"; + this.button7.Size = new System.Drawing.Size(201, 54); + this.button7.TabIndex = 7; + this.button7.Text = "inicio Proceso ProcessStartInfo"; + this.button7.UseVisualStyleBackColor = true; + this.button7.Click += new System.EventHandler(this.button7_Click); + // + // button8 + // + this.button8.Location = new System.Drawing.Point(463, 12); + this.button8.Name = "button8"; + this.button8.Size = new System.Drawing.Size(201, 54); + this.button8.TabIndex = 8; + this.button8.Text = "Propiedades"; + this.button8.UseVisualStyleBackColor = true; + this.button8.Click += new System.EventHandler(this.button8_Click); + // + // button9 + // + this.button9.Location = new System.Drawing.Point(23, 304); + this.button9.Name = "button9"; + this.button9.Size = new System.Drawing.Size(201, 52); + this.button9.TabIndex = 9; + this.button9.Text = "waitForExit()"; + this.button9.UseVisualStyleBackColor = true; + this.button9.Click += new System.EventHandler(this.button9_Click); + // + // button10 + // + this.button10.Location = new System.Drawing.Point(23, 78); + this.button10.Name = "button10"; + this.button10.Size = new System.Drawing.Size(201, 54); + this.button10.TabIndex = 10; + this.button10.Text = "Redirigir salida"; + this.button10.UseVisualStyleBackColor = true; + this.button10.Click += new System.EventHandler(this.button10_Click); + // + // button11 + // + this.button11.Location = new System.Drawing.Point(244, 78); + this.button11.Name = "button11"; + this.button11.Size = new System.Drawing.Size(201, 54); + this.button11.TabIndex = 11; + this.button11.Text = "Enviar texto a Notepad"; + this.button11.UseVisualStyleBackColor = true; + this.button11.Click += new System.EventHandler(this.button11_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button11); + this.Controls.Add(this.button10); + this.Controls.Add(this.button9); + this.Controls.Add(this.button8); + this.Controls.Add(this.button7); + this.Controls.Add(this.button6); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Button button6; + private System.Windows.Forms.Button button7; + private System.Windows.Forms.Button button8; + private System.Windows.Forms.Button button9; + private System.Windows.Forms.Button button10; + private System.Windows.Forms.Button button11; + } +} + diff --git a/01-IntroProcesos/Form1.cs b/01-IntroProcesos/Form1.cs new file mode 100644 index 0000000..db86e0a --- /dev/null +++ b/01-IntroProcesos/Form1.cs @@ -0,0 +1,132 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace _01_IntroProcesos { + public partial class Form1 : Form { + Process miProceso; + public Form1() { + InitializeComponent(); + } + + private void Button1_Click(object sender, EventArgs e) { + //referencia https://docs.microsoft.com/es-es/dotnet/api/system.diagnostics.process?view=netframework-4.8 + + miProceso = new Process(); + miProceso.StartInfo.FileName = "Notepad"; + //miProceso.StartInfo.FileName = @"C:\Program Files\LibreOffice\program\swriter.exe"; + //miProceso.StartInfo.FileName = @"C:\Program Files(x86)\Microsoft Office\Office16\WINWORD.exe"; + //miProceso.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; + miProceso.Start(); + + } + + private void Button2_Click(object sender, EventArgs e) { + miProceso.Kill(); + } + + private void Button3_Click(object sender, EventArgs e) { + Process[] misProcesos = Process.GetProcesses(); + this.comboBox1.Items.Clear(); + foreach (Process mp in misProcesos) { + this.comboBox1.Items.Add(mp.ProcessName); + } + } + + private void Button4_Click(object sender, EventArgs e) { + Process[] misProcesos = Process.GetProcessesByName("chrome"); + this.comboBox1.Items.Clear(); + foreach (Process mp in misProcesos) { + this.comboBox1.Items.Add(mp.ProcessName); + } + } + + private void Button5_Click(object sender, EventArgs e) { + Process[] misProcesos = Process.GetProcessesByName("Chrome"); + foreach (Process mp in misProcesos) { + mp.Kill(); + } + } + + private void button6_Click(object sender, EventArgs e) { + try { + Process.Start(@"C:\Windows\System32\notepad.exe"); + Process.Start("calc"); + Process.Start("MiDocumento.pdf"); + Process.Start("https:\\www.marcombo.com"); + Process.Start("C:\\"); + } + catch (Exception ex) { + Debug.WriteLine(ex.Message); + } + } + + private void button7_Click(object sender, EventArgs e) { + ProcessStartInfo psi = new ProcessStartInfo(); + psi.FileName = "ping"; + psi.CreateNoWindow = false; + psi.UseShellExecute = true; + psi.WindowStyle = ProcessWindowStyle.Maximized; + psi.Arguments = "www.marcombo.com" + " -n 10"; + try { + Process.Start(psi); + } + catch (Exception ex) { + Debug.WriteLine(ex.Message); + } + } + + private void button8_Click(object sender, EventArgs e) { + //iniciamos un proceso + miProceso = new Process(); + miProceso.StartInfo.FileName = "Notepad"; + miProceso.Start(); + + //consultamos alguna propiedad y alteramos alguna otra + Debug.WriteLine( miProceso.StartTime.ToString()); + miProceso.PriorityClass = ProcessPriorityClass.BelowNormal; + } + + private void button9_Click(object sender, EventArgs e) { + //se debe ejecutar previamente a la creación de un proceso + String nombre = miProceso.ProcessName; + Debug.WriteLine(miProceso.HasExited.ToString()); + miProceso.WaitForExit(); //método síncrono=>línea bloqueante + Debug.WriteLine(miProceso.HasExited.ToString()); + Debug.WriteLine(miProceso.ExitCode.ToString()); + Debug.WriteLine("El proceso " + nombre + "ha terminado"); + } + + private void button10_Click(object sender, EventArgs e) { + ProcessStartInfo psi = new ProcessStartInfo(); + psi.FileName = "cmd.exe"; + psi.Arguments = "/c dir"; + psi.UseShellExecute = false; + psi.CreateNoWindow = true; + psi.RedirectStandardOutput = true; + + Process p = Process.Start(psi); + StreamReader reader = p.StandardOutput; + + string datos = reader.ReadToEnd(); + Debug.WriteLine(datos); + } + + [DllImport("user32.dll", EntryPoint = "FindWindowEx")] + public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); + [DllImport("User32.dll")] + public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam); + + private void button11_Click(object sender, EventArgs e) { + Process[] processes = Process.GetProcessesByName("notepad"); + //Console.WriteLine(processes[0].MainWindowHandle.ToString()); + if (processes.Length == 0) return; + if (processes[0] != null) { + IntPtr child = FindWindowEx(processes[0].MainWindowHandle, new IntPtr(0), "Edit", null); + SendMessage(child, 0x000C, 0, "hola"); + } + } + } +} diff --git a/01-IntroProcesos/Form1.resx b/01-IntroProcesos/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/01-IntroProcesos/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/01-IntroProcesos/Program.cs b/01-IntroProcesos/Program.cs new file mode 100644 index 0000000..6302bde --- /dev/null +++ b/01-IntroProcesos/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace _01_IntroProcesos +{ + static class Program + { + /// + /// Punto de entrada principal para la aplicación. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/01-IntroProcesos/Properties/AssemblyInfo.cs b/01-IntroProcesos/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..772d32f --- /dev/null +++ b/01-IntroProcesos/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// La información general de un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie estos valores de atributo para modificar la información +// asociada con un ensamblado. +[assembly: AssemblyTitle("01-IntroProcesos")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("01-IntroProcesos")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles +// para los componentes COM. Si es necesario obtener acceso a un tipo en este ensamblado desde +// COM, establezca el atributo ComVisible en true en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM. +[assembly: Guid("afe3b6be-a35e-466e-affe-1be73de7fcac")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de compilación +// Revisión +// +// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión +// utilizando el carácter "*", como se muestra a continuación: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/01-IntroProcesos/Properties/Resources.Designer.cs b/01-IntroProcesos/Properties/Resources.Designer.cs new file mode 100644 index 0000000..9dea9df --- /dev/null +++ b/01-IntroProcesos/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Este código fue generado por una herramienta. +// Versión de runtime: 4.0.30319.42000 +// +// Los cambios de este archivo pueden provocar un comportamiento inesperado y se perderán si +// el código se vuelve a generar. +// +//------------------------------------------------------------------------------ + +namespace _01_IntroProcesos.Properties +{ + + + /// + /// Clase de recurso fuertemente tipado para buscar cadenas traducidas, etc. + /// + // StronglyTypedResourceBuilder generó automáticamente esta clase + // a través de una herramienta como ResGen o Visual Studio. + // Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen + // con la opción /str o recompile su proyecto de VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Devuelve la instancia ResourceManager almacenada en caché utilizada por esta clase. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_01_IntroProcesos.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Invalida la propiedad CurrentUICulture del subproceso actual para todas las + /// búsquedas de recursos usando esta clase de recursos fuertemente tipados. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/01-IntroProcesos/Properties/Resources.resx b/01-IntroProcesos/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/01-IntroProcesos/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/01-IntroProcesos/Properties/Settings.Designer.cs b/01-IntroProcesos/Properties/Settings.Designer.cs new file mode 100644 index 0000000..af4e376 --- /dev/null +++ b/01-IntroProcesos/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace _01_IntroProcesos.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/01-IntroProcesos/Properties/Settings.settings b/01-IntroProcesos/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/01-IntroProcesos/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/02-HelloThreads/02-HelloThreads.csproj b/02-HelloThreads/02-HelloThreads.csproj new file mode 100644 index 0000000..b7070db --- /dev/null +++ b/02-HelloThreads/02-HelloThreads.csproj @@ -0,0 +1,83 @@ + + + + + Debug + AnyCPU + {00895F8B-BA7F-4E6E-ABC8-ECFF9E18768B} + WinExe + _02_HelloThreads + 02-HelloThreads + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/02-HelloThreads/App.config b/02-HelloThreads/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/02-HelloThreads/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/02-HelloThreads/Form1.Designer.cs b/02-HelloThreads/Form1.Designer.cs new file mode 100644 index 0000000..6e9338f --- /dev/null +++ b/02-HelloThreads/Form1.Designer.cs @@ -0,0 +1,139 @@ +namespace _02_HelloThreads +{ + partial class Form1 + { + /// + /// Variable del diseñador necesaria. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Limpiar los recursos que se estén usando. + /// + /// true si los recursos administrados se deben desechar; false en caso contrario. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Código generado por el Diseñador de Windows Forms + + /// + /// Método necesario para admitir el Diseñador. No se puede modificar + /// el contenido de este método con el editor de código. + /// + private void InitializeComponent() + { + 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.button5 = new System.Windows.Forms.Button(); + this.button6 = new System.Windows.Forms.Button(); + this.button7 = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(24, 26); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(99, 43); + this.button1.TabIndex = 0; + this.button1.Text = "Hello Thread"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.Button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(152, 26); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(99, 43); + this.button2.TabIndex = 1; + this.button2.Text = "Paralelismo"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.Button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(284, 26); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(99, 43); + this.button3.TabIndex = 2; + this.button3.Text = "Variables"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.Button3_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(407, 26); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(99, 43); + this.button4.TabIndex = 3; + this.button4.Text = "Paso Parámetros"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.Button4_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(523, 26); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(99, 43); + this.button5.TabIndex = 4; + this.button5.Text = "Nombrar Hilos"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.Button5_Click); + // + // button6 + // + this.button6.Location = new System.Drawing.Point(639, 26); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(99, 43); + this.button6.TabIndex = 5; + this.button6.Text = "Propiedades"; + this.button6.UseVisualStyleBackColor = true; + this.button6.Click += new System.EventHandler(this.Button6_Click); + // + // button7 + // + this.button7.Location = new System.Drawing.Point(335, 92); + this.button7.Name = "button7"; + this.button7.Size = new System.Drawing.Size(99, 43); + this.button7.TabIndex = 6; + this.button7.Text = "Fore/Background"; + this.button7.UseVisualStyleBackColor = true; + this.button7.Click += new System.EventHandler(this.Button7_Click); + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button7); + this.Controls.Add(this.button6); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Button button6; + private System.Windows.Forms.Button button7; + } +} + diff --git a/02-HelloThreads/Form1.cs b/02-HelloThreads/Form1.cs new file mode 100644 index 0000000..3a6bccc --- /dev/null +++ b/02-HelloThreads/Form1.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Diagnostics; + +namespace _02_HelloThreads +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private void Button1_Click(object sender, EventArgs e) + { + //referencia pag 9 threading.pdf + Thread t = new Thread(this.Go); + t.Start(); + + this.Go(); + } + + private void Go() + { + Debug.WriteLine("Hola"); + } + + private void Button2_Click(object sender, EventArgs e) + { + Thread t = new Thread(this.EscribeY); + t.Start(); + for (int i = 0; i < 1000; i++) + { + Debug.Write("X"); + } + + } + + private void EscribeY() + { + for (int i=0; i<1000; i++) + { + Debug.Write("y"); + } + } + + bool Done; + private void Button3_Click(object sender, EventArgs e) + { + this.Done = false; + Thread t = new Thread(this.GoFeito); + t.Start(); + this.GoFeito(); + } + + private void GoFeito() + { + if (!Done) + { + Debug.WriteLine("Ola, está Feito"); + this.Done = true; + } + } + + private void Button4_Click(object sender, EventArgs e) + { + //primera forma de pasar parámetros + Thread t1 = new Thread( () => this.Mensaje ("Adrián") ); + t1.Start(); + + //segunda forma de pasar parámetros + Thread t2 = new Thread(this.Mensaje2); + t2.Start("Marcos"); + + this.Mensaje("JuanJosé"); + } + + private void Mensaje(string nombre) + { + Debug.WriteLine("Hola " + nombre); + } + + private void Mensaje2(object nombre) + { + String n = (string) nombre; + Debug.WriteLine("Hola " + n); + } + + private void Button5_Click(object sender, EventArgs e) + { + Thread t = new Thread(this.GoIdentificador); + t.Name = "hilo secundario"; + t.Start(); + + Thread.CurrentThread.Name = "PRINCIPAL"; + this.GoIdentificador(); + + } + + private void GoIdentificador() + { + Debug.WriteLine("Hola desde: " + Thread.CurrentThread.Name); + } + + private void Button6_Click(object sender, EventArgs e) + { + Thread.CurrentThread.Priority = ThreadPriority.Highest; + + Thread t = new Thread(this.EscribeY); + t.Priority = ThreadPriority.Lowest; + t.Start(); + + for (int i = 0; i < 1000; i++) + { + Debug.Write("X"); + } + } + + private void Button7_Click(object sender, EventArgs e) + { + Thread t = new Thread(this.LongGo); + t.IsBackground = true; + t.Start(); + } + + private void LongGo() + { + for (int i = 0; i < 1000; i++) + { + Thread.Sleep(500); + Debug.Write("y"); + } + } + } +} diff --git a/02-HelloThreads/Form1.resx b/02-HelloThreads/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/02-HelloThreads/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/02-HelloThreads/Program.cs b/02-HelloThreads/Program.cs new file mode 100644 index 0000000..64302d0 --- /dev/null +++ b/02-HelloThreads/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace _02_HelloThreads +{ + static class Program + { + /// + /// Punto de entrada principal para la aplicación. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/02-HelloThreads/Properties/AssemblyInfo.cs b/02-HelloThreads/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..83c1fb6 --- /dev/null +++ b/02-HelloThreads/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// La información general de un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie estos valores de atributo para modificar la información +// asociada con un ensamblado. +[assembly: AssemblyTitle("02-HelloThreads")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("02-HelloThreads")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles +// para los componentes COM. Si es necesario obtener acceso a un tipo en este ensamblado desde +// COM, establezca el atributo ComVisible en true en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM. +[assembly: Guid("00895f8b-ba7f-4e6e-abc8-ecff9e18768b")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de compilación +// Revisión +// +// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión +// utilizando el carácter "*", como se muestra a continuación: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/02-HelloThreads/Properties/Resources.Designer.cs b/02-HelloThreads/Properties/Resources.Designer.cs new file mode 100644 index 0000000..cdb9e57 --- /dev/null +++ b/02-HelloThreads/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Este código fue generado por una herramienta. +// Versión de runtime: 4.0.30319.42000 +// +// Los cambios de este archivo pueden provocar un comportamiento inesperado y se perderán si +// el código se vuelve a generar. +// +//------------------------------------------------------------------------------ + +namespace _02_HelloThreads.Properties +{ + + + /// + /// Clase de recurso fuertemente tipado para buscar cadenas traducidas, etc. + /// + // StronglyTypedResourceBuilder generó automáticamente esta clase + // a través de una herramienta como ResGen o Visual Studio. + // Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen + // con la opción /str o recompile su proyecto de VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Devuelve la instancia ResourceManager almacenada en caché utilizada por esta clase. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_02_HelloThreads.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Invalida la propiedad CurrentUICulture del subproceso actual para todas las + /// búsquedas de recursos usando esta clase de recursos fuertemente tipados. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/02-HelloThreads/Properties/Resources.resx b/02-HelloThreads/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/02-HelloThreads/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/02-HelloThreads/Properties/Settings.Designer.cs b/02-HelloThreads/Properties/Settings.Designer.cs new file mode 100644 index 0000000..9fdb6f9 --- /dev/null +++ b/02-HelloThreads/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace _02_HelloThreads.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/02-HelloThreads/Properties/Settings.settings b/02-HelloThreads/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/02-HelloThreads/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/03-ThreadSincro/03-ThreadSincro.csproj b/03-ThreadSincro/03-ThreadSincro.csproj new file mode 100644 index 0000000..4fe42c8 --- /dev/null +++ b/03-ThreadSincro/03-ThreadSincro.csproj @@ -0,0 +1,83 @@ + + + + + Debug + AnyCPU + {36162286-86B2-49C9-981F-BEE67CBDCB8A} + WinExe + _03_ThreadSincro + 03-ThreadSincro + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/03-ThreadSincro/App.config b/03-ThreadSincro/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/03-ThreadSincro/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/03-ThreadSincro/Form1.Designer.cs b/03-ThreadSincro/Form1.Designer.cs new file mode 100644 index 0000000..fc509df --- /dev/null +++ b/03-ThreadSincro/Form1.Designer.cs @@ -0,0 +1,134 @@ +namespace _03_ThreadSincro +{ + partial class Form1 + { + /// + /// Variable del diseñador necesaria. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Limpiar los recursos que se estén usando. + /// + /// true si los recursos administrados se deben desechar; false en caso contrario. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Código generado por el Diseñador de Windows Forms + + /// + /// Método necesario para admitir el Diseñador. No se puede modificar + /// el contenido de este método con el editor de código. + /// + private void InitializeComponent() + { + 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.button5 = new System.Windows.Forms.Button(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(26, 24); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(111, 39); + this.button1.TabIndex = 0; + this.button1.Text = "Rellena Array"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.Button1_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(26, 82); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(111, 39); + this.button2.TabIndex = 1; + this.button2.Text = "Monitor"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.Button2_Click); + // + // button3 + // + this.button3.Location = new System.Drawing.Point(26, 145); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(111, 39); + this.button3.TabIndex = 2; + this.button3.Text = "Ping Pong"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.Button3_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(26, 199); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(111, 39); + this.button4.TabIndex = 3; + this.button4.Text = "Abortar"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.Button4_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(26, 255); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(111, 46); + this.button5.TabIndex = 4; + this.button5.Text = "Interactuar Formulario"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.Button5_Click); + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(154, 255); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(126, 20); + this.textBox1.TabIndex = 5; + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(154, 281); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(126, 20); + this.textBox2.TabIndex = 6; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.button5); + this.Controls.Add(this.button4); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Name = "Form1"; + this.Text = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + } +} + diff --git a/03-ThreadSincro/Form1.cs b/03-ThreadSincro/Form1.cs new file mode 100644 index 0000000..58ad0d8 --- /dev/null +++ b/03-ThreadSincro/Form1.cs @@ -0,0 +1,214 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace _03_ThreadSincro +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + private int[] numeros = new int[1000]; + int iterador; + int numero; + private void Button1_Click(object sender, EventArgs e) + { + iterador = 0; + numero = 0; + //creo + Thread t1 = new Thread(this.rellena); + Thread t2 = new Thread(this.rellena); + Thread t3 = new Thread(this.rellena); + Thread t4 = new Thread(this.rellena); + Thread t5 = new Thread(this.rellena); + + //inicializar + t1.Start(); + t2.Start(); + t3.Start(); + t4.Start(); + t5.Start(); + + //espera + t1.Join(); + t2.Join(); + t3.Join(); + t4.Join(); + t5.Join(); + + for (int i = 0; i < 1000; i++) + { + Debug.WriteLine(numeros[i]); + } + } + Object o = new object(); + private void rellena() + { + for (int i = 0; i < 200; i++) + { + lock (o) + { + numero++; + numeros[iterador] = numero; + Thread.Sleep(50); + iterador++; + } + } + } + + private void Button2_Click(object sender, EventArgs e) + { + Thread t1 = new Thread(this.rellenaM); + Thread t2 = new Thread(this.leeM); + t1.Start(); + t2.Start(); + } + + //método asociado al hilo productor + private void rellenaM() + { + for (int i = 999; i >=0 ; i--) + { + numeros[i] = i; + Thread.Sleep(5); + } + lock(this) + Monitor.Pulse(this); + } + + //método asociado al hilo consumidor + private void leeM() + { + lock (this) + Monitor.Wait(this); + for (int i = 0; i < 1000; i++) + { + Debug.WriteLine(numeros[i]); + } + } + + private void Button3_Click(object sender, EventArgs e) + { + Thread t1 = new Thread(this.Ping); + Thread t2 = new Thread(this.Pong); + t1.Start(); + t2.Start(); + + } + + object o1 = new object(); + object o2 = new object(); + + private void Ping() + { + + for (int i = 0; i < 1000; i++) + { + lock (o2) + Monitor.Pulse(o2); + lock (o1) + { + Monitor.Wait(o1); + Debug.WriteLine("ping"); + } + } + } + + private void Pong() + { + for (int i = 0; i < 1000; i++) + { + lock (o1) + Monitor.Pulse(o1); + lock (o2) + { + Monitor.Wait(o2); + Debug.WriteLine("PONG"); + } + } + } + + private void Button4_Click(object sender, EventArgs e) + { + iterador = 0; + numero = 0; + //creo + Thread t1 = new Thread(this.rellena); + Thread t2 = new Thread(this.rellena); + Thread t3 = new Thread(this.rellena); + Thread t4 = new Thread(this.rellena); + Thread t5 = new Thread(this.rellena); + + t1.IsBackground = true; + t2.IsBackground = true; + t3.IsBackground = true; + t4.IsBackground = true; + t5.IsBackground = true; + + //inicializar + t1.Start(); + t2.Start(); + t3.Start(); + t4.Start(); + t5.Start(); + Debug.WriteLine(t1.ThreadState.ToString()); + + Thread.Sleep(200); + if (t1.IsAlive) Debug.WriteLine("xxxxxxxxxxxxxx"); + t1.Abort(); + if (t1.IsAlive) Debug.WriteLine("yyyyyyyyyyyyy"); + + } + + private void Button5_Click(object sender, EventArgs e) + { + //de esta forma no funcionaría + //Thread t1 = new Thread(this.EscribeText1); + //t1.Start(); + + Thread t1 = new Thread(this.EscribeText2); + t1.Start(); + + } + + private void EscribeText1() + { + this.textBox1.Text = "Hola"; + } + + delegate void DelegadoText(); + + delegate void DelegadoTextParametros(string s); + + private void EscribeText2() + { + //invocación delegado sin parámetros + DelegadoText dc1 = new DelegadoText(this.Escribir); + this.Invoke(dc1); + + //invocación a un delgado con parámetros + DelegadoTextParametros dc2 = new DelegadoTextParametros(this.Escribir2); + this.Invoke(dc2, "hola con parámetros"); + } + + private void Escribir() + { + this.textBox1.Text = "TEXTO"; + } + private void Escribir2(string s) + { + this.textBox2.Text = s; + } + } +} diff --git a/03-ThreadSincro/Form1.resx b/03-ThreadSincro/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/03-ThreadSincro/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/03-ThreadSincro/Program.cs b/03-ThreadSincro/Program.cs new file mode 100644 index 0000000..5604885 --- /dev/null +++ b/03-ThreadSincro/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace _03_ThreadSincro +{ + static class Program + { + /// + /// Punto de entrada principal para la aplicación. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/03-ThreadSincro/Properties/AssemblyInfo.cs b/03-ThreadSincro/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3d74f0c --- /dev/null +++ b/03-ThreadSincro/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// La información general de un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie estos valores de atributo para modificar la información +// asociada con un ensamblado. +[assembly: AssemblyTitle("03-ThreadSincro")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("03-ThreadSincro")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si establece ComVisible en false, los tipos de este ensamblado no estarán visibles +// para los componentes COM. Si es necesario obtener acceso a un tipo en este ensamblado desde +// COM, establezca el atributo ComVisible en true en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como id. de typelib si este proyecto se expone a COM. +[assembly: Guid("36162286-86b2-49c9-981f-bee67cbdcb8a")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de compilación +// Revisión +// +// Puede especificar todos los valores o usar los valores predeterminados de número de compilación y de revisión +// utilizando el carácter "*", como se muestra a continuación: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/03-ThreadSincro/Properties/Resources.Designer.cs b/03-ThreadSincro/Properties/Resources.Designer.cs new file mode 100644 index 0000000..bd76bc1 --- /dev/null +++ b/03-ThreadSincro/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Este código fue generado por una herramienta. +// Versión de runtime: 4.0.30319.42000 +// +// Los cambios de este archivo pueden provocar un comportamiento inesperado y se perderán si +// el código se vuelve a generar. +// +//------------------------------------------------------------------------------ + +namespace _03_ThreadSincro.Properties +{ + + + /// + /// Clase de recurso fuertemente tipado para buscar cadenas traducidas, etc. + /// + // StronglyTypedResourceBuilder generó automáticamente esta clase + // a través de una herramienta como ResGen o Visual Studio. + // Para agregar o quitar un miembro, edite el archivo .ResX y, a continuación, vuelva a ejecutar ResGen + // con la opción /str o recompile su proyecto de VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Devuelve la instancia ResourceManager almacenada en caché utilizada por esta clase. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_03_ThreadSincro.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Invalida la propiedad CurrentUICulture del subproceso actual para todas las + /// búsquedas de recursos usando esta clase de recursos fuertemente tipados. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/03-ThreadSincro/Properties/Resources.resx b/03-ThreadSincro/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/03-ThreadSincro/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/03-ThreadSincro/Properties/Settings.Designer.cs b/03-ThreadSincro/Properties/Settings.Designer.cs new file mode 100644 index 0000000..515f977 --- /dev/null +++ b/03-ThreadSincro/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace _03_ThreadSincro.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/03-ThreadSincro/Properties/Settings.settings b/03-ThreadSincro/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/03-ThreadSincro/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Procesos.sln b/Procesos.sln new file mode 100644 index 0000000..a3cab90 --- /dev/null +++ b/Procesos.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28729.10 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "01-IntroProcesos", "01-IntroProcesos\01-IntroProcesos.csproj", "{AFE3B6BE-A35E-466E-AFFE-1BE73DE7FCAC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "02-HelloThreads", "02-HelloThreads\02-HelloThreads.csproj", "{00895F8B-BA7F-4E6E-ABC8-ECFF9E18768B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "03-ThreadSincro", "03-ThreadSincro\03-ThreadSincro.csproj", "{36162286-86B2-49C9-981F-BEE67CBDCB8A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AFE3B6BE-A35E-466E-AFFE-1BE73DE7FCAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AFE3B6BE-A35E-466E-AFFE-1BE73DE7FCAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AFE3B6BE-A35E-466E-AFFE-1BE73DE7FCAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AFE3B6BE-A35E-466E-AFFE-1BE73DE7FCAC}.Release|Any CPU.Build.0 = Release|Any CPU + {00895F8B-BA7F-4E6E-ABC8-ECFF9E18768B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {00895F8B-BA7F-4E6E-ABC8-ECFF9E18768B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {00895F8B-BA7F-4E6E-ABC8-ECFF9E18768B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {00895F8B-BA7F-4E6E-ABC8-ECFF9E18768B}.Release|Any CPU.Build.0 = Release|Any CPU + {36162286-86B2-49C9-981F-BEE67CBDCB8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36162286-86B2-49C9-981F-BEE67CBDCB8A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36162286-86B2-49C9-981F-BEE67CBDCB8A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36162286-86B2-49C9-981F-BEE67CBDCB8A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E899D1C0-BA4E-4621-B82C-CC913F352B2E} + EndGlobalSection +EndGlobal