Threads og synkronisering
Hej Alle,Når jeg skriver til textboxen, så låser systemet. Er der nogle der kan hjælpe.
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Runtime.CompilerServices;
namespace SmartDeviceApplication5
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
public System.Windows.Forms.TextBox textBox1;
Thread test;
private ManualResetEvent allDone = new ManualResetEvent(true);
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
test = new Thread(new ThreadStart(proc));
test.Start();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.textBox1 = new System.Windows.Forms.TextBox();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(40, 64);
this.textBox1.Multiline = true;
this.textBox1.Size = new System.Drawing.Size(176, 56);
this.textBox1.Text = "textBox1";
//
// Form1
//
this.Controls.Add(this.textBox1);
this.Menu = this.mainMenu1;
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new Form1());
}
public void proc()
{
while(true)
{
Monitor.Enter(textBox1);
textBox1.Text = "Kasper";
Monitor.Exit(textBox1);
}
}
}
}
